I think it would be helpful if String#capitalize could capitalize sentences, and not just the first letter of a string. We could optionally pass a regexp to identify sentence boundaries. If we don't pass this parameter capitalize behaves as before.
I am not sure what would it take to implement this.
I hacked up a quick, and dirty implementation in Ruby.
class String
alias _capitalize capitalize
def capitalize(regexp=nil)
return _capitalize unless regexp
return split(regexp).zip(scan(regexp)).map(&:join).map(&:_capitalize).join
end
end
Hmm, how about this?
str.gsub(/\w.*?.!?/){|c|c.capitalize}
This solves my problem better than what I was doing. Thanks. Do you
think that other's could also benefit from such an extension to capitalize, or is it better done problem specific?
Of course, this is wrong for example "iPhone is designed by Apple in California."
Hmm, how about this?
str.gsub(/\w.*?.!?/){|c|c.capitalize}
This solves my problem better than what I was doing. Thanks. Do you
think that other's could also benefit from such an extension to capitalize, or is it better done problem specific?
As my example, this can't be perfect.
Such function should be provided by third party, like gems.
Hmm, how about this?
str.gsub(/\w.*?.!?/){|c|c.capitalize}
This solves my problem better than what I was doing. Thanks. Do you
think that other's could also benefit from such an extension to capitalize, or is it better done problem specific?
We have discussed this issue at today's developers' meeting in Akihabara.
This kind of processing is not only dependent on language, but even for a specific language needs a lot of information to do a reasonable job. To do it perfectly seems to require human intervention. Therefore, we think it is better if requirements like this are addressed with problem-specific solutions. We are therefore rejecting this issue.