]> git.cworth.org Git - sup/commitdiff
better string pluralization and email parsing methods (latter not used in this patch)
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Thu, 8 Nov 2007 22:44:06 +0000 (22:44 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Thu, 8 Nov 2007 22:44:06 +0000 (22:44 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@686 5c8cc53c-5e98-4d25-b20a-d8db53a31250

lib/sup/modes/contact-list-mode.rb
lib/sup/modes/thread-index-mode.rb
lib/sup/poll.rb
lib/sup/util.rb

index 86ae63ccffb54f3feaec5fb458a38affdd26a1ff..036369e2fe9e3ed32b313f3947576bbb6a4861cc 100644 (file)
@@ -59,7 +59,7 @@ class ContactListMode < LineCursorMode
     @num += num
     load
     update
-    BufferManager.flash "Added #{num} contacts."
+    BufferManager.flash "Added #{num.pluralize 'contact'}."
   end
 
   def multi_select people
index e7640003e5ded2b3232cfd7c10fc736afe2928dc..06ab1e86846ad14fe7af80bb072e4e9d737e2977 100644 (file)
@@ -309,7 +309,7 @@ EOS
       hide_thread t
     end
     regen_text
-    BufferManager.flash "Thread#{threads.size == 1 ? '' : 's'} killed."
+    BufferManager.flash "#{threads.size.pluralize 'Thread'} killed."
   end
 
   def save
@@ -412,7 +412,7 @@ EOS
     last_update = Time.now
     @ts.load_n_threads(@ts.size + n, opts) do |i|
       if (Time.now - last_update) >= 0.25
-        BufferManager.say "Loaded #{i} threads...", @mbid
+        BufferManager.say "Loaded #{i.pluralize 'thread'}...", @mbid
         update
         BufferManager.draw_screen
         last_update = Time.now
@@ -442,7 +442,7 @@ EOS
     myopts = @load_thread_opts.merge({ :when_done => (lambda do |num|
       opts[:when_done].call(num) if opts[:when_done]
       if num > 0
-        BufferManager.flash "Found #{num} threads."
+        BufferManager.flash "Found #{num.pluralize 'thread'}."
       else
         BufferManager.flash "No matches."
       end
index fb7b54608791215660f588091532f92d5c427177..34feeabedc3da619a56a6dc94906b26317146a8a 100644 (file)
@@ -50,7 +50,7 @@ EOS
     BufferManager.flash "Polling for new messages..."
     num, numi, from_and_subj, from_and_subj_inbox = buffer.mode.poll
     if num > 0
-      BufferManager.flash "Loaded #{num} new messages, #{numi} to inbox." 
+      BufferManager.flash "Loaded #{num.pluralize 'new message'}, #{numi} to inbox." 
     else
       BufferManager.flash "No new messages." 
     end
index 64457d87ebc8c56dab30b02fb0dabfc6fb177bfa..952e0e5f672c2e033e5e046b8496c9865c545b88 100644 (file)
@@ -192,6 +192,7 @@ class String
     ret
   end
 
+  ## one of the few things i miss from perl
   def ucfirst
     self[0 .. 0].upcase + self[1 .. -1]
   end
@@ -202,6 +203,65 @@ class String
     split(/,\s*(?=(?:[^"]*"[^"]*")*(?![^"]*"))/)
   end
 
+  ## ok, here we do it the hard way. got to have a remainder for purposes of
+  ## tab-completing full email addresses
+  def split_on_commas_with_remainder
+    ret = []
+    state = :outstring
+    pos = 0
+    region_start = 0
+    while pos <= length
+      newpos = case state
+        when :escaped_instring, :escaped_outstring: pos
+        else index(/[,"\\]/, pos)
+      end 
+      
+      if newpos
+        char = self[newpos]
+      else
+        char = nil
+        newpos = length
+      end
+        
+      $stderr.puts "pos #{newpos} (len #{length}), state #{state}, char #{(char || ?$).chr}, region_start #{region_start}"
+      case char
+      when ?"
+        state = case state
+          when :outstring: :instring
+          when :instring: :outstring
+          when :escaped_instring: :instring
+          when :escaped_outstring: :outstring
+        end
+      when ?,, nil
+        state = case state
+          when :outstring, :escaped_outstring:
+            ret << self[region_start ... newpos]
+            region_start = newpos + 1
+            :outstring
+          when :instring: :instring
+          when :escaped_instring: :instring
+        end
+      when ?\\
+        state = case state
+          when :instring: :escaped_instring
+          when :outstring: :escaped_outstring
+          when :escaped_instring: :instring
+          when :escaped_outstring: :outstring
+        end
+      end
+      pos = newpos + 1
+    end
+
+    remainder = case state
+      when :instring
+        self[region_start .. -1]
+      else
+        nil
+      end
+
+    [ret, remainder]
+  end
+
   def wrap len
     ret = []
     s = self
@@ -250,6 +310,10 @@ class Fixnum
       "<#{self}>"
     end
   end
+
+  def pluralize s
+    to_s + " " + (self == 1 ? s : s + "s")
+  end
 end
 
 class Hash