Class: String

Inherits:
Object show all
Includes:
ActiveSupport::CoreExtensions::String::Access, ActiveSupport::CoreExtensions::String::Behavior, ActiveSupport::CoreExtensions::String::Conversions, ActiveSupport::CoreExtensions::String::Filters, ActiveSupport::CoreExtensions::String::Inflections, ActiveSupport::CoreExtensions::String::Iterators, ActiveSupport::CoreExtensions::String::Multibyte, ActiveSupport::CoreExtensions::String::StartsEndsWith
Defined in:
lib/active_support/core_ext/blank.rb,
lib/active_support/core_ext/string.rb,
lib/active_support/json/encoders/string.rb,
lib/active_support/vendor/builder-2.1.2/builder/xchar.rb,
lib/active_support/vendor/memcache-client-1.5.1/memcache.rb

Overview

Enhance the String class with a XML escaped character version of to_s.

Instance Method Summary collapse

Methods included from ActiveSupport::CoreExtensions::String::Multibyte

#chars, #is_utf8?, #mb_chars

Methods included from ActiveSupport::CoreExtensions::String::Behavior

#acts_like_string?

Methods included from ActiveSupport::CoreExtensions::String::Iterators

append_features, #each_char

Methods included from ActiveSupport::CoreExtensions::String::StartsEndsWith

append_features, #ends_with?, #starts_with?

Methods included from ActiveSupport::CoreExtensions::String::Inflections

#camelize, #classify, #constantize, #dasherize, #demodulize, #foreign_key, #humanize, #parameterize, #pluralize, #singularize, #tableize, #titleize, #underscore

Methods included from ActiveSupport::CoreExtensions::String::Filters

#squish, #squish!

Methods included from ActiveSupport::CoreExtensions::String::Conversions

#ord, #to_date, #to_datetime, #to_time

Methods included from ActiveSupport::CoreExtensions::String::Access

#at, #first, #from, #last, #to

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)

49
50
51
# File 'lib/active_support/core_ext/blank.rb', line 49

def blank?
  self !~ /\S/
end

#crc32_ITU_TObject

Uses the ITU-T polynomial in the CRC32 algorithm.


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/active_support/vendor/memcache-client-1.5.1/memcache.rb', line 40

def crc32_ITU_T
  n = length
  r = 0xFFFFFFFF

  n.times do |i|
    r ^= self[i]
    8.times do
      if (r & 1) != 0 then
        r = (r>>1) ^ 0xEDB88320
      else
        r >>= 1
      end
    end
  end

  r ^ 0xFFFFFFFF
end

#to_json(options = nil) ⇒ Object

:nodoc:


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/active_support/json/encoders/string.rb', line 25

def to_json(options = nil) #:nodoc:
  json = '"' + gsub(ActiveSupport::JSON::Encoding.escape_regex) { |s|
    ActiveSupport::JSON::Encoding::ESCAPED_CHARS[s]
  }
  json.force_encoding('ascii-8bit') if respond_to?(:force_encoding)
  json.gsub(/([\xC0-\xDF][\x80-\xBF]|
           [\xE0-\xEF][\x80-\xBF]{2}|
           [\xF0-\xF7][\x80-\xBF]{3})+/nx) { |s|
    s.unpack("U*").pack("n*").unpack("H*")[0].gsub(/.{4}/, '\\\\u\&')
  } + '"'
end

#to_xsObject

XML escaped version of to_s


110
111
112
113
114
# File 'lib/active_support/vendor/builder-2.1.2/builder/xchar.rb', line 110

def to_xs
  unpack('U*').map {|n| n.xchr}.join # ASCII, UTF-8
rescue
  unpack('C*').map {|n| n.xchr}.join # ISO-8859-1, WIN-1252
end