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

Function recogStringToIndex

deps/leptonica/src/recogbasic.c:694–728  ·  view source on GitHub ↗

! * \brief recogStringToIndex() * * \param[in] recog * \param[in] text text string for some class * \param[out] pindex index for that class; -1 if not found * \return 0 if OK, 1 on error not finding the string is an error */

Source from the content-addressed store, hash-verified

692 * \return 0 if OK, 1 on error not finding the string is an error
693 */
694l_int32
695recogStringToIndex(L_RECOG *recog,
696 char *text,
697 l_int32 *pindex)
698{
699char *charstr;
700l_int32 i, n, diff;
701
702 PROCNAME("recogStringtoIndex");
703
704 if (!pindex)
705 return ERROR_INT("&index not defined", procName, 1);
706 *pindex = -1;
707 if (!recog)
708 return ERROR_INT("recog not defined", procName, 1);
709 if (!text)
710 return ERROR_INT("text not defined", procName, 1);
711
712 /* Search existing characters */
713 n = recog->setsize;
714 for (i = 0; i < n; i++) {
715 recogGetClassString(recog, i, &charstr);
716 if (!charstr) {
717 L_ERROR("string not found for index %d\n", procName, i);
718 continue;
719 }
720 diff = strcmp(text, charstr);
721 LEPT_FREE(charstr);
722 if (diff) continue;
723 *pindex = i;
724 return 0;
725 }
726
727 return 1; /* not found */
728}
729
730
731/*!

Callers

nothing calls this directly

Calls 1

recogGetClassStringFunction · 0.85

Tested by

no test coverage detected