Class: String

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'ext/sin_fast_blank/sin_fast_blank.c', line 54

static VALUE rb_str_blank(VALUE str) {
  char *ptr = RSTRING_PTR(str);
  if (!ptr || RSTRING_LEN(str) == 0) return Qtrue;

  char *end = RSTRING_END(str);
  rb_encoding *enc = STR_ENC_GET(str);
  while (ptr < end) {
    int len;
    unsigned int codepoint = rb_enc_codepoint_len(ptr, end, &len, enc);

    if (!rb_isspace(codepoint) && codepoint != 0) return Qfalse;

    ptr += len;
  }

  return Qtrue;
}

#blank_as?Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'ext/sin_fast_blank/sin_fast_blank.c', line 6

static VALUE rb_str_blank_as(VALUE str) {
  char *ptr = RSTRING_PTR(str);
  if (!ptr || RSTRING_LEN(str) == 0) return Qtrue;

  char *end = RSTRING_END(str);
  rb_encoding *enc = STR_ENC_GET(str);

  while (ptr < end) {
    int len;
    unsigned int codepoint = rb_enc_codepoint_len(ptr, end, &len, enc);

    switch (codepoint) {
      case 9:
      case 0xa:
      case 0xb:
      case 0xc:
      case 0xd:
      case 0x20:
      case 0x85:
      case 0xa0:
      case 0x1680:
      case 0x2000:
      case 0x2001:
      case 0x2002:
      case 0x2003:
      case 0x2004:
      case 0x2005:
      case 0x2006:
      case 0x2007:
      case 0x2008:
      case 0x2009:
      case 0x200a:
      case 0x2028:
      case 0x2029:
      case 0x202f:
      case 0x205f:
      case 0x3000:
        break;
      default:
        return Qfalse;
    }

    ptr += len;
  }

  return Qtrue;
}