yarp 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -1
  3. data/Makefile +5 -1
  4. data/config.yml +156 -125
  5. data/docs/encoding.md +5 -5
  6. data/docs/serialization.md +2 -2
  7. data/ext/yarp/api_node.c +142 -98
  8. data/ext/yarp/extension.c +21 -7
  9. data/ext/yarp/extension.h +1 -1
  10. data/include/yarp/ast.h +327 -18
  11. data/include/yarp/defines.h +2 -1
  12. data/include/yarp/diagnostic.h +3 -3
  13. data/include/yarp/enc/yp_encoding.h +10 -10
  14. data/include/yarp/parser.h +19 -19
  15. data/include/yarp/regexp.h +1 -1
  16. data/include/yarp/unescape.h +4 -4
  17. data/include/yarp/util/yp_buffer.h +3 -0
  18. data/include/yarp/util/yp_char.h +16 -16
  19. data/include/yarp/util/yp_constant_pool.h +2 -2
  20. data/include/yarp/util/yp_newline_list.h +5 -5
  21. data/include/yarp/util/yp_string.h +4 -4
  22. data/include/yarp/util/yp_string_list.h +0 -3
  23. data/include/yarp/util/yp_strpbrk.h +1 -1
  24. data/include/yarp/version.h +2 -2
  25. data/include/yarp.h +5 -4
  26. data/lib/yarp/desugar_visitor.rb +59 -122
  27. data/lib/yarp/node.rb +230 -240
  28. data/lib/yarp/serialize.rb +16 -16
  29. data/lib/yarp.rb +5 -5
  30. data/src/diagnostic.c +1 -1
  31. data/src/enc/yp_big5.c +15 -42
  32. data/src/enc/yp_euc_jp.c +16 -43
  33. data/src/enc/yp_gbk.c +19 -46
  34. data/src/enc/yp_shift_jis.c +16 -43
  35. data/src/enc/yp_tables.c +36 -38
  36. data/src/enc/yp_unicode.c +20 -25
  37. data/src/enc/yp_windows_31j.c +16 -43
  38. data/src/node.c +1271 -899
  39. data/src/prettyprint.c +87 -48
  40. data/src/regexp.c +21 -21
  41. data/src/serialize.c +28 -15
  42. data/src/unescape.c +151 -121
  43. data/src/util/yp_buffer.c +7 -2
  44. data/src/util/yp_char.c +34 -34
  45. data/src/util/yp_constant_pool.c +4 -4
  46. data/src/util/yp_memchr.c +1 -1
  47. data/src/util/yp_newline_list.c +5 -4
  48. data/src/util/yp_string.c +22 -20
  49. data/src/util/yp_string_list.c +0 -6
  50. data/src/util/yp_strncasecmp.c +3 -6
  51. data/src/util/yp_strpbrk.c +8 -8
  52. data/src/yarp.c +355 -216
  53. data/yarp.gemspec +1 -1
  54. metadata +2 -2
@@ -21,7 +21,7 @@ end
21
21
  module YARP
22
22
  module Serialize
23
23
  MAJOR_VERSION = 0
24
- MINOR_VERSION = 9
24
+ MINOR_VERSION = 10
25
25
  PATCH_VERSION = 0
26
26
 
27
27
  def self.load(input, serialized)
@@ -226,17 +226,17 @@ module YARP
226
226
  when 22 then
227
227
  ClassNode.new(Array.new(load_varint) { load_constant }, load_location, load_node, load_optional_location, load_optional_node, load_optional_node, load_location, load_string, location)
228
228
  when 23 then
229
- ClassVariableAndWriteNode.new(load_location, load_location, load_node, location)
229
+ ClassVariableAndWriteNode.new(load_constant, load_location, load_location, load_node, location)
230
230
  when 24 then
231
- ClassVariableOperatorWriteNode.new(load_location, load_location, load_node, load_constant, location)
231
+ ClassVariableOperatorWriteNode.new(load_constant, load_location, load_location, load_node, load_constant, location)
232
232
  when 25 then
233
- ClassVariableOrWriteNode.new(load_location, load_location, load_node, location)
233
+ ClassVariableOrWriteNode.new(load_constant, load_location, load_location, load_node, location)
234
234
  when 26 then
235
- ClassVariableReadNode.new(location)
235
+ ClassVariableReadNode.new(load_constant, location)
236
236
  when 27 then
237
- ClassVariableTargetNode.new(location)
237
+ ClassVariableTargetNode.new(load_constant, location)
238
238
  when 28 then
239
- ClassVariableWriteNode.new(load_location, load_optional_node, load_optional_location, location)
239
+ ClassVariableWriteNode.new(load_constant, load_location, load_optional_node, load_optional_location, location)
240
240
  when 29 then
241
241
  ConstantAndWriteNode.new(load_location, load_location, load_node, location)
242
242
  when 30 then
@@ -301,7 +301,7 @@ module YARP
301
301
  when 59 then
302
302
  GlobalVariableTargetNode.new(location)
303
303
  when 60 then
304
- GlobalVariableWriteNode.new(load_location, load_location, load_node, location)
304
+ GlobalVariableWriteNode.new(load_location, load_node, load_location, location)
305
305
  when 61 then
306
306
  HashNode.new(load_location, Array.new(load_varint) { load_node }, load_location, location)
307
307
  when 62 then
@@ -313,17 +313,17 @@ module YARP
313
313
  when 65 then
314
314
  InNode.new(load_node, load_optional_node, load_location, load_optional_location, location)
315
315
  when 66 then
316
- InstanceVariableAndWriteNode.new(load_location, load_location, load_node, location)
316
+ InstanceVariableAndWriteNode.new(load_constant, load_location, load_location, load_node, location)
317
317
  when 67 then
318
- InstanceVariableOperatorWriteNode.new(load_location, load_location, load_node, load_constant, location)
318
+ InstanceVariableOperatorWriteNode.new(load_constant, load_location, load_location, load_node, load_constant, location)
319
319
  when 68 then
320
- InstanceVariableOrWriteNode.new(load_location, load_location, load_node, location)
320
+ InstanceVariableOrWriteNode.new(load_constant, load_location, load_location, load_node, location)
321
321
  when 69 then
322
- InstanceVariableReadNode.new(location)
322
+ InstanceVariableReadNode.new(load_constant, location)
323
323
  when 70 then
324
- InstanceVariableTargetNode.new(location)
324
+ InstanceVariableTargetNode.new(load_constant, location)
325
325
  when 71 then
326
- InstanceVariableWriteNode.new(load_location, load_node, load_location, location)
326
+ InstanceVariableWriteNode.new(load_constant, load_location, load_node, load_location, location)
327
327
  when 72 then
328
328
  IntegerNode.new(location)
329
329
  when 73 then
@@ -353,7 +353,7 @@ module YARP
353
353
  when 85 then
354
354
  LocalVariableTargetNode.new(load_constant, load_varint, location)
355
355
  when 86 then
356
- LocalVariableWriteNode.new(load_constant, load_varint, load_node, load_location, load_location, location)
356
+ LocalVariableWriteNode.new(load_constant, load_varint, load_location, load_node, load_location, location)
357
357
  when 87 then
358
358
  MatchPredicateNode.new(load_node, load_node, load_location, location)
359
359
  when 88 then
@@ -371,7 +371,7 @@ module YARP
371
371
  when 94 then
372
372
  NoKeywordsParameterNode.new(load_location, load_location, location)
373
373
  when 95 then
374
- NumberedReferenceReadNode.new(location)
374
+ NumberedReferenceReadNode.new(load_varint, location)
375
375
  when 96 then
376
376
  OptionalParameterNode.new(load_constant, load_location, load_location, load_node, location)
377
377
  when 97 then
data/lib/yarp.rb CHANGED
@@ -462,10 +462,10 @@ module YARP
462
462
  # order here so that we can compare properly.
463
463
  if params
464
464
  sorted = [
465
- *params.requireds.grep(RequiredParameterNode).map(&:constant_id),
466
- *params.optionals.map(&:constant_id),
465
+ *params.requireds.grep(RequiredParameterNode).map(&:name),
466
+ *params.optionals.map(&:name),
467
467
  *((params.rest.name ? params.rest.name.to_sym : :*) if params.rest && params.rest.operator != ","),
468
- *params.posts.grep(RequiredParameterNode).map(&:constant_id),
468
+ *params.posts.grep(RequiredParameterNode).map(&:name),
469
469
  *params.keywords.reject(&:value).map { |param| param.name.chomp(":").to_sym },
470
470
  *params.keywords.select(&:value).map { |param| param.name.chomp(":").to_sym }
471
471
  ]
@@ -485,9 +485,9 @@ module YARP
485
485
  when RequiredDestructuredParameterNode
486
486
  param_stack.concat(param.parameters.reverse)
487
487
  when RequiredParameterNode
488
- sorted << param.constant_id
488
+ sorted << param.name
489
489
  when SplatNode
490
- sorted << param.expression.constant_id if param.expression
490
+ sorted << param.expression.name if param.expression
491
491
  end
492
492
  end
493
493
 
data/src/diagnostic.c CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  // Append an error to the given list of diagnostic.
4
4
  bool
5
- yp_diagnostic_list_append(yp_list_t *list, const char *start, const char *end, const char *message) {
5
+ yp_diagnostic_list_append(yp_list_t *list, const uint8_t *start, const uint8_t *end, const char *message) {
6
6
  yp_diagnostic_t *diagnostic = (yp_diagnostic_t *) malloc(sizeof(yp_diagnostic_t));
7
7
  if (diagnostic == NULL) return false;
8
8
 
data/src/enc/yp_big5.c CHANGED
@@ -1,69 +1,42 @@
1
1
  #include "yarp/enc/yp_encoding.h"
2
2
 
3
- typedef uint16_t yp_big5_codepoint_t;
4
-
5
- static yp_big5_codepoint_t
6
- yp_big5_codepoint(const char *c, ptrdiff_t n, size_t *width) {
7
- const unsigned char *uc = (const unsigned char *) c;
8
-
3
+ static size_t
4
+ yp_encoding_big5_char_width(const uint8_t *b, ptrdiff_t n) {
9
5
  // These are the single byte characters.
10
- if (*uc < 0x80) {
11
- *width = 1;
12
- return *uc;
6
+ if (*b < 0x80) {
7
+ return 1;
13
8
  }
14
9
 
15
10
  // These are the double byte characters.
16
- if ((n > 1) && (uc[0] >= 0xA1 && uc[0] <= 0xFE) && (uc[1] >= 0x40 && uc[1] <= 0xFE)) {
17
- *width = 2;
18
- return (yp_big5_codepoint_t) (uc[0] << 8 | uc[1]);
11
+ if ((n > 1) && (b[0] >= 0xA1 && b[0] <= 0xFE) && (b[1] >= 0x40 && b[1] <= 0xFE)) {
12
+ return 2;
19
13
  }
20
14
 
21
- *width = 0;
22
15
  return 0;
23
16
  }
24
17
 
25
18
  static size_t
26
- yp_encoding_big5_char_width(const char *c, ptrdiff_t n) {
27
- size_t width;
28
- yp_big5_codepoint(c, n, &width);
29
-
30
- return width;
31
- }
32
-
33
- static size_t
34
- yp_encoding_big5_alpha_char(const char *c, ptrdiff_t n) {
35
- size_t width;
36
- yp_big5_codepoint_t codepoint = yp_big5_codepoint(c, n, &width);
37
-
38
- if (width == 1) {
39
- const char value = (const char) codepoint;
40
- return yp_encoding_ascii_alpha_char(&value, n);
19
+ yp_encoding_big5_alpha_char(const uint8_t *b, ptrdiff_t n) {
20
+ if (yp_encoding_big5_char_width(b, n) == 1) {
21
+ return yp_encoding_ascii_alpha_char(b, n);
41
22
  } else {
42
23
  return 0;
43
24
  }
44
25
  }
45
26
 
46
27
  static size_t
47
- yp_encoding_big5_alnum_char(const char *c, ptrdiff_t n) {
48
- size_t width;
49
- yp_big5_codepoint_t codepoint = yp_big5_codepoint(c, n, &width);
50
-
51
- if (width == 1) {
52
- const char value = (const char) codepoint;
53
- return yp_encoding_ascii_alnum_char(&value, n);
28
+ yp_encoding_big5_alnum_char(const uint8_t *b, ptrdiff_t n) {
29
+ if (yp_encoding_big5_char_width(b, n) == 1) {
30
+ return yp_encoding_ascii_alnum_char(b, n);
54
31
  } else {
55
32
  return 0;
56
33
  }
57
34
  }
58
35
 
59
36
  static bool
60
- yp_encoding_big5_isupper_char(const char *c, ptrdiff_t n) {
61
- size_t width;
62
- yp_big5_codepoint_t codepoint = yp_big5_codepoint(c, n, &width);
63
-
64
- if (width == 1) {
65
- const char value = (const char) codepoint;
66
- return yp_encoding_ascii_isupper_char(&value, n);
37
+ yp_encoding_big5_isupper_char(const uint8_t *b, ptrdiff_t n) {
38
+ if (yp_encoding_big5_char_width(b, n) == 1) {
39
+ return yp_encoding_ascii_isupper_char(b, n);
67
40
  } else {
68
41
  return false;
69
42
  }
data/src/enc/yp_euc_jp.c CHANGED
@@ -1,75 +1,48 @@
1
1
  #include "yarp/enc/yp_encoding.h"
2
2
 
3
- typedef uint16_t yp_euc_jp_codepoint_t;
4
-
5
- static yp_euc_jp_codepoint_t
6
- yp_euc_jp_codepoint(const char *c, ptrdiff_t n, size_t *width) {
7
- const unsigned char *uc = (const unsigned char *) c;
8
-
3
+ static size_t
4
+ yp_encoding_euc_jp_char_width(const uint8_t *b, ptrdiff_t n) {
9
5
  // These are the single byte characters.
10
- if (*uc < 0x80) {
11
- *width = 1;
12
- return *uc;
6
+ if (*b < 0x80) {
7
+ return 1;
13
8
  }
14
9
 
15
10
  // These are the double byte characters.
16
11
  if (
17
12
  (n > 1) &&
18
13
  (
19
- ((uc[0] == 0x8E) && (uc[1] >= 0xA1 && uc[1] <= 0xFE)) ||
20
- ((uc[0] >= 0xA1 && uc[0] <= 0xFE) && (uc[1] >= 0xA1 && uc[1] <= 0xFE))
14
+ ((b[0] == 0x8E) && (b[1] >= 0xA1 && b[1] <= 0xFE)) ||
15
+ ((b[0] >= 0xA1 && b[0] <= 0xFE) && (b[1] >= 0xA1 && b[1] <= 0xFE))
21
16
  )
22
17
  ) {
23
- *width = 2;
24
- return (yp_euc_jp_codepoint_t) (uc[0] << 8 | uc[1]);
18
+ return 2;
25
19
  }
26
20
 
27
- *width = 0;
28
21
  return 0;
29
22
  }
30
23
 
31
24
  static size_t
32
- yp_encoding_euc_jp_char_width(const char *c, ptrdiff_t n) {
33
- size_t width;
34
- yp_euc_jp_codepoint(c, n, &width);
35
-
36
- return width;
37
- }
38
-
39
- static size_t
40
- yp_encoding_euc_jp_alpha_char(const char *c, ptrdiff_t n) {
41
- size_t width;
42
- yp_euc_jp_codepoint_t codepoint = yp_euc_jp_codepoint(c, n, &width);
43
-
44
- if (width == 1) {
45
- const char value = (const char) codepoint;
46
- return yp_encoding_ascii_alpha_char(&value, n);
25
+ yp_encoding_euc_jp_alpha_char(const uint8_t *b, ptrdiff_t n) {
26
+ if (yp_encoding_euc_jp_char_width(b, n) == 1) {
27
+ return yp_encoding_ascii_alpha_char(b, n);
47
28
  } else {
48
29
  return 0;
49
30
  }
50
31
  }
51
32
 
52
33
  static size_t
53
- yp_encoding_euc_jp_alnum_char(const char *c, ptrdiff_t n) {
54
- size_t width;
55
- yp_euc_jp_codepoint_t codepoint = yp_euc_jp_codepoint(c, n, &width);
56
-
57
- if (width == 1) {
58
- const char value = (const char) codepoint;
59
- return yp_encoding_ascii_alnum_char(&value, n);
34
+ yp_encoding_euc_jp_alnum_char(const uint8_t *b, ptrdiff_t n) {
35
+ if (yp_encoding_euc_jp_char_width(b, n) == 1) {
36
+ return yp_encoding_ascii_alnum_char(b, n);
60
37
  } else {
61
38
  return 0;
62
39
  }
63
40
  }
64
41
 
65
42
  static bool
66
- yp_encoding_euc_jp_isupper_char(const char *c, ptrdiff_t n) {
67
- size_t width;
68
- yp_euc_jp_codepoint_t codepoint = yp_euc_jp_codepoint(c, n, &width);
69
-
70
- if (width == 1) {
71
- const char value = (const char) codepoint;
72
- return yp_encoding_ascii_isupper_char(&value, n);
43
+ yp_encoding_euc_jp_isupper_char(const uint8_t *b, ptrdiff_t n) {
44
+ if (yp_encoding_euc_jp_char_width(b, n) == 1) {
45
+ return yp_encoding_ascii_isupper_char(b, n);
73
46
  } else {
74
47
  return 0;
75
48
  }
data/src/enc/yp_gbk.c CHANGED
@@ -1,78 +1,51 @@
1
1
  #include "yarp/enc/yp_encoding.h"
2
2
 
3
- typedef uint16_t yp_gbk_codepoint_t;
4
-
5
- static yp_gbk_codepoint_t
6
- yp_gbk_codepoint(const char *c, ptrdiff_t n, size_t *width) {
7
- const unsigned char *uc = (const unsigned char *) c;
8
-
3
+ static size_t
4
+ yp_encoding_gbk_char_width(const uint8_t *b, ptrdiff_t n) {
9
5
  // These are the single byte characters.
10
- if (*uc < 0x80) {
11
- *width = 1;
12
- return *uc;
6
+ if (*b < 0x80) {
7
+ return 1;
13
8
  }
14
9
 
15
10
  // These are the double byte characters.
16
11
  if (
17
12
  (n > 1) &&
18
13
  (
19
- ((uc[0] >= 0xA1 && uc[0] <= 0xA9) && (uc[1] >= 0xA1 && uc[1] <= 0xFE)) || // GBK/1
20
- ((uc[0] >= 0xB0 && uc[0] <= 0xF7) && (uc[1] >= 0xA1 && uc[1] <= 0xFE)) || // GBK/2
21
- ((uc[0] >= 0x81 && uc[0] <= 0xA0) && (uc[1] >= 0x40 && uc[1] <= 0xFE) && (uc[1] != 0x7F)) || // GBK/3
22
- ((uc[0] >= 0xAA && uc[0] <= 0xFE) && (uc[1] >= 0x40 && uc[1] <= 0xA0) && (uc[1] != 0x7F)) || // GBK/4
23
- ((uc[0] >= 0xA8 && uc[0] <= 0xA9) && (uc[1] >= 0x40 && uc[1] <= 0xA0) && (uc[1] != 0x7F)) // GBK/5
14
+ ((b[0] >= 0xA1 && b[0] <= 0xA9) && (b[1] >= 0xA1 && b[1] <= 0xFE)) || // GBK/1
15
+ ((b[0] >= 0xB0 && b[0] <= 0xF7) && (b[1] >= 0xA1 && b[1] <= 0xFE)) || // GBK/2
16
+ ((b[0] >= 0x81 && b[0] <= 0xA0) && (b[1] >= 0x40 && b[1] <= 0xFE) && (b[1] != 0x7F)) || // GBK/3
17
+ ((b[0] >= 0xAA && b[0] <= 0xFE) && (b[1] >= 0x40 && b[1] <= 0xA0) && (b[1] != 0x7F)) || // GBK/4
18
+ ((b[0] >= 0xA8 && b[0] <= 0xA9) && (b[1] >= 0x40 && b[1] <= 0xA0) && (b[1] != 0x7F)) // GBK/5
24
19
  )
25
20
  ) {
26
- *width = 2;
27
- return (yp_gbk_codepoint_t) (uc[0] << 8 | uc[1]);
21
+ return 2;
28
22
  }
29
23
 
30
- *width = 0;
31
24
  return 0;
32
25
  }
33
26
 
34
27
  static size_t
35
- yp_encoding_gbk_char_width(const char *c, ptrdiff_t n) {
36
- size_t width;
37
- yp_gbk_codepoint(c, n, &width);
38
-
39
- return width;
40
- }
41
-
42
- static size_t
43
- yp_encoding_gbk_alpha_char(const char *c, ptrdiff_t n) {
44
- size_t width;
45
- yp_gbk_codepoint_t codepoint = yp_gbk_codepoint(c, n, &width);
46
-
47
- if (width == 1) {
48
- const char value = (const char) codepoint;
49
- return yp_encoding_ascii_alpha_char(&value, n);
28
+ yp_encoding_gbk_alpha_char(const uint8_t *b, ptrdiff_t n) {
29
+ if (yp_encoding_gbk_char_width(b, n) == 1) {
30
+ return yp_encoding_ascii_alpha_char(b, n);
50
31
  } else {
51
32
  return 0;
52
33
  }
53
34
  }
54
35
 
55
36
  static size_t
56
- yp_encoding_gbk_alnum_char(const char *c, ptrdiff_t n) {
57
- size_t width;
58
- yp_gbk_codepoint_t codepoint = yp_gbk_codepoint(c, n, &width);
59
-
60
- if (width == 1) {
61
- const char value = (const char) codepoint;
62
- return yp_encoding_ascii_alnum_char(&value, n);
37
+ yp_encoding_gbk_alnum_char(const uint8_t *b, ptrdiff_t n) {
38
+ if (yp_encoding_gbk_char_width(b, n) == 1) {
39
+ return yp_encoding_ascii_alnum_char(b, n);
63
40
  } else {
64
41
  return 0;
65
42
  }
66
43
  }
67
44
 
68
45
  static bool
69
- yp_encoding_gbk_isupper_char(const char *c, ptrdiff_t n) {
70
- size_t width;
71
- yp_gbk_codepoint_t codepoint = yp_gbk_codepoint(c, n, &width);
72
-
73
- if (width == 1) {
74
- const char value = (const char) codepoint;
75
- return yp_encoding_ascii_isupper_char(&value, n);
46
+ yp_encoding_gbk_isupper_char(const uint8_t *b, ptrdiff_t n) {
47
+ if (yp_encoding_gbk_char_width(b, n) == 1) {
48
+ return yp_encoding_ascii_isupper_char(b, n);
76
49
  } else {
77
50
  return false;
78
51
  }
@@ -1,73 +1,46 @@
1
1
  #include "yarp/enc/yp_encoding.h"
2
2
 
3
- typedef uint16_t yp_shift_jis_codepoint_t;
4
-
5
- static yp_shift_jis_codepoint_t
6
- yp_shift_jis_codepoint(const char *c, ptrdiff_t n, size_t *width) {
7
- const unsigned char *uc = (const unsigned char *) c;
8
-
3
+ static size_t
4
+ yp_encoding_shift_jis_char_width(const uint8_t *b, ptrdiff_t n) {
9
5
  // These are the single byte characters.
10
- if (*uc < 0x80 || (*uc >= 0xA1 && *uc <= 0xDF)) {
11
- *width = 1;
12
- return *uc;
6
+ if (*b < 0x80 || (*b >= 0xA1 && *b <= 0xDF)) {
7
+ return 1;
13
8
  }
14
9
 
15
10
  // These are the double byte characters.
16
11
  if (
17
12
  (n > 1) &&
18
- ((uc[0] >= 0x81 && uc[0] <= 0x9F) || (uc[0] >= 0xE0 && uc[0] <= 0xFC)) &&
19
- (uc[1] >= 0x40 && uc[1] <= 0xFC)
13
+ ((b[0] >= 0x81 && b[0] <= 0x9F) || (b[0] >= 0xE0 && b[0] <= 0xFC)) &&
14
+ (b[1] >= 0x40 && b[1] <= 0xFC)
20
15
  ) {
21
- *width = 2;
22
- return (yp_shift_jis_codepoint_t) (uc[0] << 8 | uc[1]);
16
+ return 2;
23
17
  }
24
18
 
25
- *width = 0;
26
19
  return 0;
27
20
  }
28
21
 
29
22
  static size_t
30
- yp_encoding_shift_jis_char_width(const char *c, ptrdiff_t n) {
31
- size_t width;
32
- yp_shift_jis_codepoint(c, n, &width);
33
-
34
- return width;
35
- }
36
-
37
- static size_t
38
- yp_encoding_shift_jis_alpha_char(const char *c, ptrdiff_t n) {
39
- size_t width;
40
- yp_shift_jis_codepoint_t codepoint = yp_shift_jis_codepoint(c, n, &width);
41
-
42
- if (width == 1) {
43
- const char value = (const char) codepoint;
44
- return yp_encoding_ascii_alpha_char(&value, n);
23
+ yp_encoding_shift_jis_alpha_char(const uint8_t *b, ptrdiff_t n) {
24
+ if (yp_encoding_shift_jis_char_width(b, n) == 1) {
25
+ return yp_encoding_ascii_alpha_char(b, n);
45
26
  } else {
46
27
  return 0;
47
28
  }
48
29
  }
49
30
 
50
31
  static size_t
51
- yp_encoding_shift_jis_alnum_char(const char *c, ptrdiff_t n) {
52
- size_t width;
53
- yp_shift_jis_codepoint_t codepoint = yp_shift_jis_codepoint(c, n, &width);
54
-
55
- if (width == 1) {
56
- const char value = (const char) codepoint;
57
- return yp_encoding_ascii_alnum_char(&value, n);
32
+ yp_encoding_shift_jis_alnum_char(const uint8_t *b, ptrdiff_t n) {
33
+ if (yp_encoding_shift_jis_char_width(b, n) == 1) {
34
+ return yp_encoding_ascii_alnum_char(b, n);
58
35
  } else {
59
36
  return 0;
60
37
  }
61
38
  }
62
39
 
63
40
  static bool
64
- yp_encoding_shift_jis_isupper_char(const char *c, ptrdiff_t n) {
65
- size_t width;
66
- yp_shift_jis_codepoint_t codepoint = yp_shift_jis_codepoint(c, n, &width);
67
-
68
- if (width == 1) {
69
- const char value = (const char) codepoint;
70
- return yp_encoding_ascii_isupper_char(&value, n);
41
+ yp_encoding_shift_jis_isupper_char(const uint8_t *b, ptrdiff_t n) {
42
+ if (yp_encoding_shift_jis_char_width(b, n) == 1) {
43
+ return yp_encoding_ascii_isupper_char(b, n);
71
44
  } else {
72
45
  return 0;
73
46
  }