src/textops.c
SARRAY *
splitStringToParagraphs(char    *textstr,
                        l_int32  splitflag)
{
char    *linestr, *parastring;
l_int32  nlines, i, allwhite, leadwhite;
SARRAY  *salines, *satemp, *saout;

    PROCNAME("splitStringToParagraphs");

    if (!textstr)
        return (SARRAY *)ERROR_PTR("textstr not defined", procName, NULL);

    if ((salines = sarrayCreateLinesFromString(textstr, 1)) == NULL)
        return (SARRAY *)ERROR_PTR("salines not made", procName, NULL);
    nlines = sarrayGetCount(salines);
    saout = sarrayCreate(0);
    satemp = sarrayCreate(0);

    linestr = sarrayGetString(salines, 0, 0);
    sarrayAddString(satemp, linestr, 1);
    for (i = 1; i < nlines; i++) {
        linestr = sarrayGetString(salines, i, 0);
        stringAllWhitespace(linestr, &allwhite);
        stringLeadingWhitespace(linestr, &leadwhite);
        if ((splitflag == SPLIT_ON_LEADING_WHITE && leadwhite) ||
            (splitflag == SPLIT_ON_BLANK_LINE && allwhite) ||
            (splitflag == SPLIT_ON_BOTH && (allwhite || leadwhite))) {
            parastring = sarrayToString(satemp, 1);  /* add nl to each line */
            sarrayAddString(saout, parastring, 0);  /* insert */
            sarrayDestroy(&satemp);
            satemp = sarrayCreate(0);
        }
        sarrayAddString(satemp, linestr, 1);
    }
    parastring = sarrayToString(satemp, 1);  /* add nl to each line */
    sarrayAddString(saout, parastring, 0);  /* insert */
    sarrayDestroy(&satemp);

    return saout;
}
/*!
 *  splitStringToParagraphs()
 *
 *      Input:  textstring
 *              splitting flag (see enum in bmf.h; valid values in {1,2,3})
 *      Return: sarray (where each string is a paragraph of the input),
 *                      or null on error.
 */
splitStringToParagraphs()
Input:  textstring
splitting flag
Return: sarray (where each string is a paragraph of the input),
or null on error.
splitStringToParagraphs () Input : textstring splitting flag Return : sarray ( where each string is a paragraph of the input ) or null on error .
SARRAY *
splitStringToParagraphs(char    *textstr,
                        l_int32  splitflag)
{
char    *linestr, *parastring;
l_int32  nlines, i, allwhite, leadwhite;
SARRAY  *salines, *satemp, *saout;
    PROCNAME("splitStringToParagraphs");
    if (!textstr)
        return (SARRAY *)ERROR_PTR("textstr not defined", procName, NULL);
    if ((salines = sarrayCreateLinesFromString(textstr, 1)) == NULL)
        return (SARRAY *)ERROR_PTR("salines not made", procName, NULL);
    nlines = sarrayGetCount(salines);
    saout = sarrayCreate(0);
    satemp = sarrayCreate(0);
    linestr = sarrayGetString(salines, 0, 0);
    sarrayAddString(satemp, linestr, 1);
    for (i = 1; i < nlines; i++) {
        linestr = sarrayGetString(salines, i, 0);
        stringAllWhitespace(linestr, &allwhite);
        stringLeadingWhitespace(linestr, &leadwhite);
        if ((splitflag == SPLIT_ON_LEADING_WHITE && leadwhite) ||
            (splitflag == SPLIT_ON_BLANK_LINE && allwhite) ||
            (splitflag == SPLIT_ON_BOTH && (allwhite || leadwhite))) {
            parastring = sarrayToString(satemp, 1);  
            sarrayAddString(saout, parastring, 0);  
            sarrayDestroy(&satemp);
            satemp = sarrayCreate(0);
        }
        sarrayAddString(satemp, linestr, 1);
    }
    parastring = sarrayToString(satemp, 1);  
    sarrayAddString(saout, parastring, 0);  
    sarrayDestroy(&satemp);
    return saout;
}
SARRAY * splitStringToParagraphs ( char * textstr , l_int32 splitflag ) { char * linestr , * parastring ; l_int32 nlines , i , allwhite , leadwhite ; SARRAY * salines , * satemp , * saout ; PROCNAME ( " " ) ; if ( ! textstr ) return ( SARRAY * ) ERROR_PTR ( " " , procName , NULL ) ; if ( ( salines = sarrayCreateLinesFromString ( textstr , 1 ) ) == NULL ) return ( SARRAY * ) ERROR_PTR ( " " , procName , NULL ) ; nlines = sarrayGetCount ( salines ) ; saout = sarrayCreate ( 0 ) ; satemp = sarrayCreate ( 0 ) ; linestr = sarrayGetString ( salines , 0 , 0 ) ; sarrayAddString ( satemp , linestr , 1 ) ; for ( i = 1 ; i < nlines ; i ++ ) { linestr = sarrayGetString ( salines , i , 0 ) ; stringAllWhitespace ( linestr , & allwhite ) ; stringLeadingWhitespace ( linestr , & leadwhite ) ; if ( ( splitflag == SPLIT_ON_LEADING_WHITE && leadwhite ) || ( splitflag == SPLIT_ON_BLANK_LINE && allwhite ) || ( splitflag == SPLIT_ON_BOTH && ( allwhite || leadwhite ) ) ) { parastring = sarrayToString ( satemp , 1 ) ; sarrayAddString ( saout , parastring , 0 ) ; sarrayDestroy ( & satemp ) ; satemp = sarrayCreate ( 0 ) ; } sarrayAddString ( satemp , linestr , 1 ) ; } parastring = sarrayToString ( satemp , 1 ) ; sarrayAddString ( saout , parastring , 0 ) ; sarrayDestroy ( & satemp ) ; return saout ; }
splitStringToParagraphs()
      Input:  textstring
              splitting flag (see enum in bmf.h; valid values in {1,2,3})
      Return: sarray (where each string is a paragraph of the input),
                      or null on error.
splitStringToParagraphs () Input : textstring splitting flag ( see enum in bmf . h ; valid values in { 1 2 3 } ) Return : sarray ( where each string is a paragraph of the input ) or null on error .
/* add nl to each line */ /* insert */ /* add nl to each line */ /* insert */