MCPcopy Create free account
hub / github.com/creatale/node-dv / sarrayParseRange

Function sarrayParseRange

deps/leptonica/src/sarray1.c:1259–1332  ·  view source on GitHub ↗

! * \brief sarrayParseRange() * * \param[in] sa input sarray * \param[in] start index to start range search * \param[out] pactualstart index of actual start; may be > 'start' * \param[out] pend index of end * \param[out] pnewstart index of start of next range * \param[in] substr substring for matching at beginning of string * \param[in] loc byte offset within the string f

Source from the content-addressed store, hash-verified

1257 * </pre>
1258 */
1259l_int32
1260sarrayParseRange(SARRAY *sa,
1261 l_int32 start,
1262 l_int32 *pactualstart,
1263 l_int32 *pend,
1264 l_int32 *pnewstart,
1265 const char *substr,
1266 l_int32 loc)
1267{
1268char *str;
1269l_int32 n, i, offset, found;
1270
1271 PROCNAME("sarrayParseRange");
1272
1273 if (!sa)
1274 return ERROR_INT("sa not defined", procName, 1);
1275 if (!pactualstart || !pend || !pnewstart)
1276 return ERROR_INT("not all range addresses defined", procName, 1);
1277 n = sarrayGetCount(sa);
1278 *pactualstart = *pend = *pnewstart = n;
1279 if (!substr)
1280 return ERROR_INT("substr not defined", procName, 1);
1281
1282 /* Look for the first string without the marker */
1283 if (start < 0 || start >= n)
1284 return 1;
1285 for (i = start; i < n; i++) {
1286 str = sarrayGetString(sa, i, L_NOCOPY);
1287 arrayFindSequence((l_uint8 *)str, strlen(str), (l_uint8 *)substr,
1288 strlen(substr), &offset, &found);
1289 if (loc < 0) {
1290 if (!found) break;
1291 } else {
1292 if (!found || offset != loc) break;
1293 }
1294 }
1295 start = i;
1296 if (i == n) /* couldn't get started */
1297 return 1;
1298
1299 /* Look for the last string without the marker */
1300 *pactualstart = start;
1301 for (i = start + 1; i < n; i++) {
1302 str = sarrayGetString(sa, i, L_NOCOPY);
1303 arrayFindSequence((l_uint8 *)str, strlen(str), (l_uint8 *)substr,
1304 strlen(substr), &offset, &found);
1305 if (loc < 0) {
1306 if (found) break;
1307 } else {
1308 if (found && offset == loc) break;
1309 }
1310 }
1311 *pend = i - 1;
1312 start = i;
1313 if (i == n) /* no further range */
1314 return 0;
1315
1316 /* Look for the first string after *pend without the marker.

Callers 5

fmorphautogen1Function · 0.85
fmorphautogen2Function · 0.85
fhmtautogen1Function · 0.85
fhmtautogen2Function · 0.85
strcodeFinalizeFunction · 0.85

Calls 3

sarrayGetCountFunction · 0.85
sarrayGetStringFunction · 0.85
arrayFindSequenceFunction · 0.85

Tested by

no test coverage detected