| 1137 | } |
| 1138 | |
| 1139 | void PiuCode_findLineBreak(xsMachine *the) |
| 1140 | { |
| 1141 | PiuCode* self = PIU(Code, xsThis); |
| 1142 | uint32_t argc = xsToUnsigned(xsArgc); |
| 1143 | int32_t result = xsToInteger(xsArg(0)); |
| 1144 | int32_t direction = (argc > 1) ? (xsToBoolean(xsArg(1)) ? +1 : -1) : + 1; |
| 1145 | if ((direction < 0) && (result == 0)) |
| 1146 | result = 0; |
| 1147 | else if ((direction > 0) && (result >= (int32_t)(*self)->length)) |
| 1148 | result = (*self)->length; |
| 1149 | else { |
| 1150 | char *s = PiuToString((*self)->string); |
| 1151 | char *p = s + fxUnicodeToUTF8Offset(s, result); |
| 1152 | char c; |
| 1153 | if (direction > 0) { |
| 1154 | result = (*self)->length; |
| 1155 | while ((c = *p)) { |
| 1156 | if ((c == 10) || (c == 13)) { |
| 1157 | result = fxUTF8ToUnicodeOffset(s, p + 1 - s); |
| 1158 | break; |
| 1159 | } |
| 1160 | p++; |
| 1161 | } |
| 1162 | } |
| 1163 | else { |
| 1164 | p--; |
| 1165 | result = 0; |
| 1166 | while (p >= s) { |
| 1167 | c = *p; |
| 1168 | if ((c == 10) || (c == 13)) { |
| 1169 | result = fxUTF8ToUnicodeOffset(s, p + 1 - s); |
| 1170 | break; |
| 1171 | } |
| 1172 | p--; |
| 1173 | } |
| 1174 | } |
| 1175 | } |
| 1176 | xsResult = xsInteger(result); |
| 1177 | } |
| 1178 | |
| 1179 | void PiuCode_findWordBreak(xsMachine *the) |
| 1180 | { |
nothing calls this directly
no test coverage detected