edn_turbo 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,7 +15,7 @@ namespace edn
15
15
  //
16
16
  // unescapes any values that need to be replaced, saves it to utf8
17
17
  //
18
- bool Parser::unicode_to_utf8(const char *s, std::size_t len, std::string& rslt)
18
+ bool Parser::to_utf8(const char *s, std::size_t len, std::string& rslt)
19
19
  {
20
20
  icu::UnicodeString ustr(s, len);
21
21
 
@@ -13,6 +13,8 @@
13
13
 
14
14
  namespace edn
15
15
  {
16
+ //
17
+ // used to determine max number of chars in string value of a type
16
18
  template <typename T>
17
19
  static std::size_t get_max_chars(T)
18
20
  {
@@ -57,19 +59,25 @@ namespace edn
57
59
  //
58
60
  // copies the string data, unescaping any present values that need to be replaced
59
61
  //
60
- bool Parser::parse_byte_stream(const char *p_start, const char *p_end, Rice::String& s)
62
+ bool Parser::parse_byte_stream(const char *p_start, const char *p_end, Rice::String& s,
63
+ bool encode)
61
64
  {
62
65
  if (p_end > p_start) {
63
66
  std::string buf;
64
67
 
65
- if (unicode_to_utf8(p_start, p_end - p_start, buf))
66
- {
67
- // utf-8 encode
68
- VALUE vs = Rice::protect( rb_str_new2, buf.c_str() );
69
- VALUE s_utf8 = Rice::protect( rb_enc_associate, vs, rb_utf8_encoding() );
70
- s = Rice::String(s_utf8);
71
- return true;
68
+ if (encode) {
69
+ if (!to_utf8(p_start, p_end - p_start, buf))
70
+ return false;
71
+ }
72
+ else {
73
+ buf.append(p_start, p_end - p_start);
72
74
  }
75
+
76
+ // utf-8 encode
77
+ VALUE vs = Rice::protect( rb_str_new2, buf.c_str() );
78
+ VALUE s_utf8 = Rice::protect( rb_enc_associate, vs, rb_utf8_encoding() );
79
+ s = Rice::String(s_utf8);
80
+ return true;
73
81
  }
74
82
 
75
83
  return false;
@@ -85,14 +93,14 @@ namespace edn
85
93
  buf.append(p, len);
86
94
 
87
95
  if (len > 1) {
88
- if (buf == "newline") buf = "\\n";
89
- else if (buf == "tab") buf = "\\t";
90
- else if (buf == "return") buf = "\\r";
91
- else if (buf == "space") buf = " ";
92
- else if (buf == "formfeed") buf = "\\f";
93
- else if (buf == "backspace") buf = "\\b";
96
+ if (buf == "newline") buf = '\n';
97
+ else if (buf == "tab") buf = '\t';
98
+ else if (buf == "return") buf = '\r';
99
+ else if (buf == "space") buf = ' ';
100
+ else if (buf == "formfeed") buf = '\f';
101
+ else if (buf == "backspace") buf = '\b';
94
102
  // TODO: is this supported?
95
- else if (buf == "verticaltab") buf = "\\v";
103
+ else if (buf == "verticaltab") buf = '\v';
96
104
  else return false;
97
105
  }
98
106
 
@@ -1,4 +1,4 @@
1
1
  module EDNT
2
- VERSION = '0.2.1'
3
- RELEASE_DATE = %q{2015-06-01}
2
+ VERSION = '0.2.2'
3
+ RELEASE_DATE = %q{2015-06-03}
4
4
  end
@@ -47,7 +47,7 @@ class EDNT_Test < Minitest::Test
47
47
 
48
48
  check_file('test/values.edn',
49
49
  [false, true, nil, "this is a test", "this\tis\\only\ta\ttest\rof\"various\nescaped\\values",
50
- "c", "\\n", "\\t",
50
+ "c", "\n", "\t",
51
51
  "123➪456®789"]
52
52
  )
53
53
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edn_turbo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed Porras
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-01 00:00:00.000000000 Z
11
+ date: 2015-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: edn
@@ -83,8 +83,8 @@ files:
83
83
  - ext/edn_turbo/edn_parser.cc
84
84
  - ext/edn_turbo/edn_parser.h
85
85
  - ext/edn_turbo/edn_parser.rl
86
- - ext/edn_turbo/edn_parser_def.cc
87
86
  - ext/edn_turbo/edn_parser_unicode.cc
87
+ - ext/edn_turbo/edn_parser_util.cc
88
88
  - ext/edn_turbo/extconf.rb
89
89
  - ext/edn_turbo/main.cc
90
90
  - lib/edn_turbo.rb