Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- (unknown)
Instance Method Summary collapse
Instance Method Details
#ascii_blank? ⇒ Boolean
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'ext/sin_fast_blank/sin_fast_blank.c', line 86 static VALUE rb_str_ascii_blank(VALUE str) { long len = RSTRING_LEN(str); if (len == 0) { return Qtrue; } const char *ptr = RSTRING_PTR(str); const char *end = ptr + len; rb_encoding *enc = STR_ENC_GET(str); if (rb_enc_asciicompat(enc)) { for (; ptr < end; ptr++) { unsigned char c = (unsigned char)*ptr; if (c >= 0x80) { goto FULL_CHECK; } if (!rb_isspace(c) && c != 0) { return Qfalse; } } return Qtrue; } FULL_CHECK:; while (ptr < end) { int clen; unsigned int codepoint = rb_enc_codepoint_len(ptr, end, &clen, enc); if (codepoint != 0 && !rb_isspace(codepoint)) { return Qfalse; } ptr += clen; } return Qtrue; } |
#blank? ⇒ Boolean
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'ext/sin_fast_blank/sin_fast_blank.c', line 39 static VALUE rb_str_blank(VALUE str) { long len = RSTRING_LEN(str); if (len == 0) { return Qtrue; } const char *ptr = RSTRING_PTR(str); const char *end = ptr + len; rb_encoding *enc = STR_ENC_GET(str); if (rb_enc_asciicompat(enc)) { for (const unsigned char *p = (const unsigned char *)ptr; p < (const unsigned char *)end; p++) { if (*p >= 0x80) { goto FULL_CHECK; } switch (*p) { case 0x9: case 0xa: case 0xb: case 0xc: case 0xd: case 0x20: break; default: return Qfalse; } } return Qtrue; } FULL_CHECK:; while (ptr < end) { int clen; unsigned int codepoint = rb_enc_codepoint_len(ptr, end, &clen, enc); if (!is_unicode_blank(codepoint)) { return Qfalse; } ptr += clen; } return Qtrue; } |