! * \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 */
| 692 | * \return 0 if OK, 1 on error not finding the string is an error |
| 693 | */ |
| 694 | l_int32 |
| 695 | recogStringToIndex(L_RECOG *recog, |
| 696 | char *text, |
| 697 | l_int32 *pindex) |
| 698 | { |
| 699 | char *charstr; |
| 700 | l_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 | /*! |
nothing calls this directly
no test coverage detected