faxmail/MsgFmt.c++
/*
 * This function replaces comments with a single white space.
 * Unclosed comments are automatically closed at end of string.
 * Stray closing parentheses are left untouched, as are other invalid chars.
 * Headers which can contain quoted strings should not go through this
 * revision of this function as is doesn't honnor them and could end up doing
 * the wrong thing.
 */
This function replaces comments with a single white space.
Unclosed comments are automatically closed at end of string.
Stray closing parentheses are left untouched, as are other invalid chars.
Headers which can contain quoted strings should not go through this
revision of this function as is doesn't honnor them and could end up doing
the wrong thing.
This function replaces comments with a single white space . Unclosed comments are automatically closed at end of string . Stray closing parentheses are left untouched as are other invalid chars . Headers which can contain quoted strings should not go through this revision of this function as is doesn ' t honnor them and could end up doing the wrong thing .
fxStr
MsgFmt::stripComments(const fxStr& s)
{
    fxStr q;
    u_int depth = 0;
    bool wasSpace = true;
    for (u_int i = 0; i < s.length(); i++) {
        switch (s[i]) {
            case '(':
                depth++;
                break;
            case ')':
                if (depth > 0)
                    depth--;
                break;
            case '\\':
                if (depth == 0) {
                    q.append(s[i++]);     
                    q.append(s[i]);
                    wasSpace = false;
                } else
                  i++;
                break;
            default:
                if (depth == 0) {
                    if (!isspace(s[i]) || !wasSpace) {       
                        q.append(s[i]);
                        wasSpace = isspace(s[i]);
                    }
                }
                break;
        }
    }
    while (q.length() > 0 && isspace(q[q.length()-1]))
      q.remove(q.length()-1, 1);      
    return q;
}
fxStr MsgFmt :: stripComments ( const fxStr & s ) { fxStr q ; u_int depth = 0 ; bool wasSpace = true ; for ( u_int i = 0 ; i < s . length ( ) ; i ++ ) { switch ( s [ i ] ) { case ' ' : depth ++ ; break ; case ' ' : if ( depth > 0 ) depth -- ; break ; case ' \\ ' : if ( depth == 0 ) { q . append ( s [ i ++ ] ) ; q . append ( s [ i ] ) ; wasSpace = false ; } else i ++ ; break ; default : if ( depth == 0 ) { if ( ! isspace ( s [ i ] ) || ! wasSpace ) { q . append ( s [ i ] ) ; wasSpace = isspace ( s [ i ] ) ; } } break ; } } while ( q . length ( ) > 0 && isspace ( q [ q . length ( ) - 1 ] ) ) q . remove ( q . length ( ) - 1 , 1 ) ; return q ; }
This function replaces comments with a single white space.
This function replaces comments with a single white space .
// Don't decode them at this time // Trim consecutive spaces // Trim trailing white space