MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / PiuCode_find

Function PiuCode_find

modules/piu/PC/Code/piuCode.c:1013–1052  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1011}
1012
1013void PiuCode_find(xsMachine *the)
1014{
1015 PiuCode* self = PIU(Code, xsThis);
1016 uint32_t argc = xsToUnsigned(xsArgc);
1017 xsStringValue pattern = NULL;
1018 xsBooleanValue caseless = 0;
1019 PiuTextBuffer* results = (*self)->results;
1020 PiuCodeResult result;
1021 if (argc > 1)
1022 caseless = xsToBoolean(xsArg(1));
1023 if (argc > 0)
1024 pattern = xsToString(xsArg(0));
1025 if ((*self)->code || (*self)->data) {
1026 fxDeleteRegExp(NULL, (*self)->code, (*self)->data);
1027 (*self)->code = NULL;
1028 (*self)->data = NULL;
1029 }
1030 if (pattern && pattern[0]) {
1031 xsStringValue modifier = (caseless) ? "imu" : "mu";
1032 fxCompileRegExp(NULL, pattern, modifier, &(*self)->code, &(*self)->data, NULL, 0);
1033 }
1034 PiuCodeSearch(self, (*self)->size);
1035 result = (PiuCodeResult)((char*)(*results) + sizeof(PiuTextBufferRecord));
1036 if (result->count >= 0) {
1037 xsResult = xsTrue;
1038 while (result->count >= 0) {
1039 if ((*self)->from <= result->from) {
1040 PiuCodeSelect(self, result->from, result->to - result->from);
1041 return;
1042 }
1043 result = (PiuCodeResult)(((char*)result) + (*self)->resultsSize);
1044 }
1045 result = (PiuCodeResult)((char*)(*results) + sizeof(PiuTextBufferRecord));
1046 PiuCodeSelect(self, result->from, result->to - result->from);
1047 }
1048 else {
1049 xsResult = xsFalse;
1050 PiuCodeSelect(self, (*self)->from, 0);
1051 }
1052}
1053
1054void PiuCode_findAgain(xsMachine *the)
1055{

Callers

nothing calls this directly

Calls 4

fxDeleteRegExpFunction · 0.85
fxCompileRegExpFunction · 0.85
PiuCodeSearchFunction · 0.85
PiuCodeSelectFunction · 0.85

Tested by

no test coverage detected