| 1 | /* |
| 2 | Copyright(C) 2018 Kouhei Sutou <[email protected]> |
| 3 | |
| 4 | This library is free software; you can redistribute it and/or |
| 5 | modify it under the terms of the GNU Lesser General Public |
| 6 | License as published by the Free Software Foundation; either |
| 7 | version 2.1 of the License, or (at your option) any later version. |
| 8 | |
| 9 | This library is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | Lesser General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU Lesser General Public |
| 15 | License along with this library; if not, write to the Free Software |
| 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 | |
| 19 | #include "grn_ctx.h"cxx . . $ `<file>/lib/grn_ctx.h`/ |
| 20 | #include "grn_onigmo.h"cxx . . $ `<file>/lib/grn_onigmo.h`/ |
| 21 | |
| 22 | #ifdef GRN_SUPPORT_REGEXPcxx . . $ `lib/grn.h:734:11`! |
| 23 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! |
| 24 | grn_onigmo_is_valid_encodingcxx . . $ grn_onigmo_is_valid_encoding(6769dd2542d68818).(grn_ctxcxx . . $ grn_ctx# *ctx) |
| 25 | { |
| 26 | switch (ctx->encodingcxx . . $ _grn_ctx#encoding.) { |
| 27 | case GRN_ENC_EUC_JPcxx . . $ GRN_ENC_EUC_JP. : |
| 28 | case GRN_ENC_UTF8cxx . . $ GRN_ENC_UTF8. : |
| 29 | case GRN_ENC_SJIScxx . . $ GRN_ENC_SJIS. : |
| 30 | case GRN_ENC_LATIN1cxx . . $ GRN_ENC_LATIN1. : |
| 31 | case GRN_ENC_KOI8Rcxx . . $ GRN_ENC_KOI8R. : |
| 32 | return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 33 | default : |
| 34 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | OnigRegexcxx . . $ OnigRegex# |
| 39 | grn_onigmo_newcxx . . $ grn_onigmo_new(5d4bcbb55fe07878).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 40 | const char *pattern, |
| 41 | size_t pattern_length, |
| 42 | OnigOptionTypecxx . . $ OnigOptionType# option, |
| 43 | const OnigSyntaxTypecxx . . $ OnigSyntaxType# *syntax, |
| 44 | const char *context) |
| 45 | { |
| 46 | OnigEncodingcxx . . $ OnigEncoding# onig_encoding; |
| 47 | OnigRegexcxx . . $ OnigRegex# onig_regex; |
| 48 | int onig_result; |
| 49 | OnigErrorInfocxx . . $ OnigErrorInfo# onig_error_info; |
| 50 | |
| 51 | switch (ctx->encodingcxx . . $ _grn_ctx#encoding.) { |
| 52 | case GRN_ENC_EUC_JPcxx . . $ GRN_ENC_EUC_JP. : |
| 53 | onig_encoding = ONIG_ENCODING_EUC_JPcxx . . $ `vendor/onigmo-source/onigmo.h:247:10`!; |
| 54 | break; |
| 55 | case GRN_ENC_UTF8cxx . . $ GRN_ENC_UTF8. : |
| 56 | onig_encoding = ONIG_ENCODING_UTF8cxx . . $ `vendor/onigmo-source/onigmo.h:274:10`!; |
| 57 | break; |
| 58 | case GRN_ENC_SJIScxx . . $ GRN_ENC_SJIS. : |
| 59 | onig_encoding = ONIG_ENCODING_CP932cxx . . $ `vendor/onigmo-source/onigmo.h:267:10`!; |
| 60 | break; |
| 61 | case GRN_ENC_LATIN1cxx . . $ GRN_ENC_LATIN1. : |
| 62 | onig_encoding = ONIG_ENCODING_ISO_8859_1cxx . . $ `vendor/onigmo-source/onigmo.h:227:10`!; |
| 63 | break; |
| 64 | case GRN_ENC_KOI8Rcxx . . $ GRN_ENC_KOI8R. : |
| 65 | onig_encoding = ONIG_ENCODING_KOI8_Rcxx . . $ `vendor/onigmo-source/onigmo.h:254:10`!; |
| 66 | break; |
| 67 | default : |
| 68 | ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, |
| 69 | "%s[regexp][new] invalid encoding: <%.*s>: <%s>", |
| 70 | context, |
| 71 | (int)pattern_length, |
| 72 | pattern, |
| 73 | grn_encoding_to_string(ctx->encoding)); |
| 74 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 75 | } |
| 76 | |
| 77 | onig_result = onig_newcxx . . $ onig_new(8407fdcc7f7ecfac).(&onig_regex, |
| 78 | pattern, |
| 79 | pattern + pattern_length, |
| 80 | option, |
| 81 | onig_encoding, |
| 82 | syntax, |
| 83 | &onig_error_info); |
| 84 | if (onig_result != ONIG_NORMALcxx . . $ `vendor/onigmo-source/onigmo.h:624:9`!) { |
| 85 | char message[ONIG_MAX_ERROR_MESSAGE_LENcxx . . $ `vendor/onigmo-source/onigmo.h:443:9`!]; |
| 86 | onig_error_code_to_strcxx . . $ onig_error_code_to_str(6d10d2bfc901f965).(message, onig_result, &onig_error_info); |
| 87 | ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, |
| 88 | "%s[regexp][new] " |
| 89 | "failed to create regular expression object: <%.*s>: %s", |
| 90 | context, |
| 91 | (int)pattern_length, |
| 92 | pattern, |
| 93 | message); |
| 94 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 95 | } |
| 96 | |
| 97 | return onig_regex; |
| 98 | } |
| 99 | |
| 100 | #endif /* GRN_SUPPORT_REGEXP */ |