commit 59b5fb611389bd84e383b128f4628d1a68a8a381
parent f9206dd537147aeb5015e81d11db13acc2efb2c2
Author: wmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Date: Thu, 8 Nov 2007 22:44:06 +0000
better string pluralization and email parsing methods (latter not used in this patch)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@686 5c8cc53c-5e98-4d25-b20a-d8db53a31250
Diffstat:
4 files changed, 69 insertions(+), 5 deletions(-)
diff --git a/lib/sup/modes/contact-list-mode.rb b/lib/sup/modes/contact-list-mode.rb
@@ -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
diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
@@ -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
diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb
@@ -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
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
@@ -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