Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/rubygoods/string.rb
Instance Method Summary collapse
Instance Method Details
#antiinject ⇒ Object
5 6 7 8 |
# File 'lib/rubygoods/string.rb', line 5 def antiinject udquote = '"'.force_encoding("UTF-8").unpack('U*').map{ |i| "\\u" + i.to_s(16).rjust(4, '0') }.join self.force_encoding("UTF-8").gsub(/"/, udquote) end |
#quotenormalize ⇒ Object
9 10 11 |
# File 'lib/rubygoods/string.rb', line 9 def quotenormalize self.force_encoding("UTF-8").gsub(/\\u0022/, '"') end |
#spliteach(num) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rubygoods/string.rb', line 12 def spliteach(num) strs = Array.new counter = 0 pos = 0 str = "" self.each_char do |c| if strs[pos] == nil strs[pos] = "" end if counter == num strs[pos] << str pos += 1 counter = 0 str = "" end str = str + c.to_s counter += 1 end if str != "" strs[pos] << str end return strs end |
#squish ⇒ Object
2 3 4 |
# File 'lib/rubygoods/string.rb', line 2 def squish self.force_encoding("UTF-8").gsub(/\s+/, " ").strip end |