! * \brief sarrayAddString() * * \param[in] sa string array * \param[in] string string to be added * \param[in] copyflag L_INSERT, L_NOCOPY or L_COPY * \return 0 if OK, 1 on error * * * Notes: * (1) See usage comments at the top of this file. L_INSERT is * equivalent to L_NOCOPY. * */
| 443 | * </pre> |
| 444 | */ |
| 445 | l_int32 |
| 446 | sarrayAddString(SARRAY *sa, |
| 447 | char *string, |
| 448 | l_int32 copyflag) |
| 449 | { |
| 450 | l_int32 n; |
| 451 | |
| 452 | PROCNAME("sarrayAddString"); |
| 453 | |
| 454 | if (!sa) |
| 455 | return ERROR_INT("sa not defined", procName, 1); |
| 456 | if (!string) |
| 457 | return ERROR_INT("string not defined", procName, 1); |
| 458 | if (copyflag != L_INSERT && copyflag != L_NOCOPY && copyflag != L_COPY) |
| 459 | return ERROR_INT("invalid copyflag", procName, 1); |
| 460 | |
| 461 | n = sarrayGetCount(sa); |
| 462 | if (n >= sa->nalloc) |
| 463 | sarrayExtendArray(sa); |
| 464 | |
| 465 | if (copyflag == L_COPY) |
| 466 | sa->array[n] = stringNew(string); |
| 467 | else /* L_INSERT or L_NOCOPY */ |
| 468 | sa->array[n] = string; |
| 469 | sa->n++; |
| 470 | |
| 471 | return 0; |
| 472 | } |
| 473 | |
| 474 | |
| 475 | /*! |
no test coverage detected