| 1 | /* |
| 2 | Copyright (C) 2016-2017 Brazil |
| 3 | Copyright (C) 2019-2022 Sutou Kouhei <[email protected]> |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with this library; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include "grn_str.h"cxx . . $ `<file>/lib/grn_str.h`/ |
| 21 | |
| 22 | void |
| 23 | grn_raw_string_lstripcxx . . $ grn_raw_string_lstrip(f337a808b82abe1c).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 24 | grn_raw_stringcxx . . $ grn_raw_string# *string) |
| 25 | { |
| 26 | const char *end; |
| 27 | int space_len; |
| 28 | |
| 29 | end = string->valuecxx . . $ $anonymous_type_7f733dd816802915_0#value. + string->lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length.; |
| 30 | while (string->valuecxx . . $ $anonymous_type_7f733dd816802915_0#value. < end) { |
| 31 | space_len = grn_isspacecxx . . $ grn_isspace(f8f88a86d74aa1ba).(string->valuecxx . . $ $anonymous_type_7f733dd816802915_0#value., ctx->encodingcxx . . $ _grn_ctx#encoding.); |
| 32 | if (space_len == 0) { |
| 33 | break; |
| 34 | } |
| 35 | string->valuecxx . . $ $anonymous_type_7f733dd816802915_0#value. += space_len; |
| 36 | string->lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length. -= (size_t)space_len; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! |
| 41 | grn_raw_string_have_sub_stringcxx . . $ grn_raw_string_have_sub_string(96682bdc7a1a05f5).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 42 | grn_raw_stringcxx . . $ grn_raw_string# *string, |
| 43 | grn_raw_stringcxx . . $ grn_raw_string# *sub_string) |
| 44 | { |
| 45 | if (sub_string->lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length. == 0) { |
| 46 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 47 | } |
| 48 | |
| 49 | if (sub_string->lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length. > string->lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length.) { |
| 50 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 51 | } |
| 52 | |
| 53 | const char *string_current = string->valuecxx . . $ $anonymous_type_7f733dd816802915_0#value.; |
| 54 | const char *string_end = string->valuecxx . . $ $anonymous_type_7f733dd816802915_0#value. + string->lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length.; |
| 55 | const char *sub_string_current = sub_string->valuecxx . . $ $anonymous_type_7f733dd816802915_0#value.; |
| 56 | const char *sub_string_end = sub_string->valuecxx . . $ $anonymous_type_7f733dd816802915_0#value. + sub_string->lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length.; |
| 57 | int sub_string_start_char_len; |
| 58 | int sub_string_char_len; |
| 59 | |
| 60 | sub_string_start_char_len = |
| 61 | grn_charlencxx . . $ grn_charlen(d229e8bf7c87f0f0).(ctx, sub_string_current, sub_string_end); |
| 62 | if (sub_string_start_char_len == 0) { |
| 63 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 64 | } |
| 65 | sub_string_char_len = sub_string_start_char_len; |
| 66 | |
| 67 | while (string_current < string_end) { |
| 68 | int string_char_len; |
| 69 | |
| 70 | string_char_len = grn_charlencxx . . $ grn_charlen(d229e8bf7c87f0f0).(ctx, string_current, string_end); |
| 71 | if (string_char_len == 0) { |
| 72 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 73 | } |
| 74 | |
| 75 | if (string_char_len == sub_string_char_len && |
| 76 | memcmpcxx . . $ memcmp(36f949851efa3055).(string_current, |
| 77 | sub_string_current, |
| 78 | (size_t)string_char_len) == 0) { |
| 79 | sub_string_current += sub_string_char_len; |
| 80 | if (sub_string_current == sub_string_end) { |
| 81 | return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 82 | } |
| 83 | |
| 84 | sub_string_char_len = grn_charlencxx . . $ grn_charlen(d229e8bf7c87f0f0).(ctx, sub_string_current, sub_string_end); |
| 85 | if (sub_string_char_len == 0) { |
| 86 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 87 | } |
| 88 | } else { |
| 89 | if (sub_string_current != sub_string->valuecxx . . $ $anonymous_type_7f733dd816802915_0#value.) { |
| 90 | sub_string_current = sub_string->valuecxx . . $ $anonymous_type_7f733dd816802915_0#value.; |
| 91 | sub_string_char_len = sub_string_start_char_len; |
| 92 | continue; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | string_current += string_char_len; |
| 97 | } |
| 98 | |
| 99 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 100 | } |
| 101 | |
| 102 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! |
| 103 | grn_raw_string_have_sub_string_cstringcxx . . $ grn_raw_string_have_sub_string_cstring(a56e835ce94c1aaf).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 104 | grn_raw_stringcxx . . $ grn_raw_string# *string, |
| 105 | const char *sub_cstring) |
| 106 | { |
| 107 | grn_raw_stringcxx . . $ grn_raw_string# sub_string; |
| 108 | if (sub_cstring) { |
| 109 | sub_string.valuecxx . . $ $anonymous_type_7f733dd816802915_0#value. = sub_cstring; |
| 110 | sub_string.lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length. = strlencxx . . $ strlen(751346f8406fd082).(sub_cstring); |
| 111 | } else { |
| 112 | sub_string.valuecxx . . $ $anonymous_type_7f733dd816802915_0#value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 113 | sub_string.lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length. = 0; |
| 114 | } |
| 115 | |
| 116 | return grn_raw_string_have_sub_stringcxx . . $ grn_raw_string_have_sub_string(96682bdc7a1a05f5).(ctx, string, &sub_string); |
| 117 | } |
| 118 | |
| 119 | grn_raw_stringcxx . . $ grn_raw_string# |
| 120 | grn_raw_string_substringcxx . . $ grn_raw_string_substring(e1fbc62d3c6092da).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 121 | const grn_raw_stringcxx . . $ grn_raw_string# *string, |
| 122 | size_t start, |
| 123 | int64_tcxx . . $ int64_t# length) |
| 124 | { |
| 125 | grn_raw_stringcxx . . $ grn_raw_string# substring; |
| 126 | substring.valuecxx . . $ $anonymous_type_7f733dd816802915_0#value. = string->valuecxx . . $ $anonymous_type_7f733dd816802915_0#value. + start; |
| 127 | if (length < 0) { |
| 128 | int64_tcxx . . $ int64_t# substring_length = (int64_tcxx . . $ int64_t#)(string->lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length. - start) + length + 1; |
| 129 | if (substring_length < 0) { |
| 130 | substring.lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length. = 0; |
| 131 | } else { |
| 132 | substring.lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length. = (size_t)substring_length; |
| 133 | } |
| 134 | } else { |
| 135 | substring.lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length. = (size_t)length; |
| 136 | } |
| 137 | return substring; |
| 138 | } |