Class: TwitterCldr::Utils::YAML

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_cldr/utils/yaml.rb

Constant Summary collapse

UCS_0X85 =

c285@UTF8 Unicode next line

[0x85].pack('U')
UCS_0XA0 =

c2a0@UTF8 Unicode non-breaking space

[0xa0].pack('U')
UCS_0X2028 =

e280a8@UTF8 Unicode line separator

[0x2028].pack('U')
UCS_0X2029 =

e280a9@UTF8 Unicode paragraph separator

[0x2029].pack('U')
ESCAPE_SEQ =

non-break characters

{
  "\x00" => '\\0',
  "\x07" => '\\a',
  "\x08" => '\\b',
  "\x0b" => '\\v',
  "\x0c" => '\\f',
  "\x1b" => '\\e',
  "\""   => '\\"',
  "\\"   => '\\\\',
}
ESCAPE_SEQ_NS =

non-breaking space

{
  UCS_0XA0 => '\\_',
}
ESCAPE_SEQ_WS =

white spaces

{
  "\x09" => '\\t',
  " "    => '\\x20',
}
ESCAPE_SEQ_LB =

line breaks

{
  "\x0a"     => '\\n',
  "\x0d"     => '\\r',
  UCS_0X85   => '\\N',
  UCS_0X2028 => '\\L',
  UCS_0X2029 => '\\P',
}
REX_LF =

regexps for line breaks

Regexp.escape("\x0a")
REX_CR =
Regexp.escape("\x0d")
REX_CRLF =
Regexp.escape("\x0d\x0a")
REX_NEL =
Regexp.escape(UCS_0X85)
REX_LS =
Regexp.escape(UCS_0X2028)
REX_PS =
Regexp.escape(UCS_0X2029)
REX_ANY_LB =
/(#{REX_LF}|#{REX_CR}|#{REX_NEL}|#{REX_LS}|#{REX_PS})/
REX_NORMAL_LB =
/(#{REX_LF}|#{REX_LS}|#{REX_PS})/
REX_BOOL =

regexps for language-Independent types for YAML1.1

/
   y|Y|yes|Yes|YES|n|N|no|No|NO
  |true|True|TRUE|false|False|FALSE
  |on|On|ON|off|Off|OFF
/x
REX_FLOAT =
/
   [-+]?([0-9][0-9_]*)?\.[0-9.]*([eE][-+][0-9]+)? # (base 10)
  |[-+]?[0-9][0-9_]*(:[0-5]?[0-9])+\.[0-9_]*      # (base 60)
  |[-+]?\.(inf|Inf|INF)                           # (infinity)
  |\.(nan|NaN|NAN)                                # (not a number)
/x
REX_INT =
/
   [-+]?0b[0-1_]+                   # (base 2)
  |[-+]?0[0-7_]+                    # (base 8)
  |[-+]?(0|[1-9][0-9_]*)            # (base 10)
  |[-+]?0x[0-9a-fA-F_]+             # (base 16)
  |[-+]?[1-9][0-9_]*(:[0-5]?[0-9])+ # (base 60)
/x
REX_MERGE =
/
  <<
/x
REX_NULL =
/
   ~              # (canonical)
  |null|Null|NULL # (English)
  |               # (Empty)
/x
REX_TIMESTAMP =
/
   [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] # (ymd)
  |[0-9][0-9][0-9][0-9]                       # (year)
   -[0-9][0-9]?                               # (month)
   -[0-9][0-9]?                               # (day)
   ([Tt]|[ \t]+)[0-9][0-9]?                   # (hour)
   :[0-9][0-9]                                # (minute)
   :[0-9][0-9]                                # (second)
   (\.[0-9]*)?                                # (fraction)
   (([ \t]*)Z|[-+][0-9][0-9]?(:[0-9][0-9])?)? # (time zone)
/x
REX_VALUE =
/
  =
/x
REX_SYMBOL =
/
  \A:.*
/x

Class Method Summary collapse

Class Method Details

.dump(obj, opts = {}) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/twitter_cldr/utils/yaml.rb', line 130

def dump(obj, opts = {})
  @options = opts.dup
  @options[:indent_size] = 2          if @options[:indent_size].to_i <= 0
  @options[:minimum_block_length] = 0 if @options[:minimum_block_length].to_i <= 0
  @options.update(
    {
      printable_with_syck:  true,
      escape_b_specific:    true,
      escape_as_utf8:       true,
    }
  ) if @options[:syck_compatible]

  "--- #{emit(obj, 1)}\n"
rescue SystemStackError
  raise ArgumentError, "TwitterCLDR yaml dumper can't handle circular references"
end