| 72 | |
| 73 | /* This function allocate the buffers, and initialize them. */ |
| 74 | |
| 75 | static reg_errcode_t |
| 76 | internal_function |
| 77 | re_string_construct (re_string_t *pstr, const char *str, int len, |
| 78 | RE_TRANSLATE_TYPE trans, int icase, const re_dfa_t *dfa) |
| 79 | { |
| 80 | reg_errcode_t ret; |
| 81 | memset (pstr, '\0', sizeof (re_string_t)); |
| 82 | re_string_construct_common (str, len, pstr, trans, icase, dfa); |
| 83 | |
| 84 | if (len > 0) |
| 85 | { |
| 86 | ret = re_string_realloc_buffers (pstr, len + 1); |
| 87 | if (BE (ret != REG_NOERROR, 0)) |
| 88 | return ret; |
| 89 | } |
| 90 | pstr->mbs = pstr->mbs_allocated ? pstr->mbs : (unsigned char *) str; |
| 91 | |
| 92 | if (icase) |
| 93 | { |
| 94 | #ifdef RE_ENABLE_I18N |
| 95 | if (dfa->mb_cur_max > 1) |
| 96 | { |
| 97 | while (1) |
| 98 | { |
| 99 | ret = build_wcs_upper_buffer (pstr); |
| 100 | if (BE (ret != REG_NOERROR, 0)) |
| 101 | return ret; |
| 102 | if (pstr->valid_raw_len >= len) |
| 103 | break; |
| 104 | if (pstr->bufs_len > pstr->valid_len + dfa->mb_cur_max) |
| 105 | break; |
| 106 | ret = re_string_realloc_buffers (pstr, pstr->bufs_len * 2); |
| 107 | if (BE (ret != REG_NOERROR, 0)) |
| 108 | return ret; |
| 109 | } |
| 110 | } |
| 111 | else |
| 112 | #endif /* RE_ENABLE_I18N */ |
| 113 | build_upper_buffer (pstr); |
| 114 | } |
| 115 | else |
| 116 | { |
| 117 | #ifdef RE_ENABLE_I18N |
| 118 | if (dfa->mb_cur_max > 1) |
| 119 | build_wcs_buffer (pstr); |
| 120 | else |
| 121 | #endif /* RE_ENABLE_I18N */ |
| 122 | { |
| 123 | if (trans != NULL) |
| 124 | re_string_translate_buffer (pstr); |
| 125 | else |
| 126 | { |
| 127 | pstr->valid_len = pstr->bufs_len; |
| 128 | pstr->valid_raw_len = pstr->bufs_len; |
| 129 | } |
| 130 | } |
| 131 | } |
no test coverage detected