/* * Bridge: trim */ c_t * STRING_trim( c_t * p_s ) { c_t result[ESCHER_SYS_MAX_STRING_LEN]; result[0] = '\0'; c_t * a; c_t * b; // find the first non whitespace character a = p_s; for ( ; *a != '\0'; a++ ) { if ( *a != ' ' && *a != '\r' && *a != '\t' && *a != '\n' ) break; // found non whitespace } // find last non whitespace character i_t len = (i_t)Escher_strlen( p_s ); b = p_s + ( len - 1 ); for ( ; b != p_s; b-- ) { if ( *a != ' ' && *a != '\r' && *a != '\t' && *a != '\n' ) break; // found non whitespace } // check if they crossed ( all whitespace ) if ( b < a ) { return result; } else { return STRING_substr( (const i_t)(a - p_s), (const i_t)(b - p_s)+1, p_s ); } }
/* * Bridge: trim */ c_t * STRING_trim( c_t A0xtumlsret[ESCHER_SYS_MAX_STRING_LEN], c_t p_s[ESCHER_SYS_MAX_STRING_LEN] ) { i_t len = strlen( p_s ); A0xtumlsret[0] = '\0'; c_t * a; c_t * b; // find the first non whitespace character a = p_s; for ( ; *a != '\0'; a++ ) { if ( *a != ' ' && *a != '\r' && *a != '\t' && *a != '\n' ) break; // found non whitespace } // find last non whitespace character b = p_s + ( len - 1 ); for ( ; b != p_s; b-- ) { if ( *a != ' ' && *a != '\r' && *a != '\t' && *a != '\n' ) break; // found non whitespace } // check if they crossed ( all whitespace ) if ( b >= a ) { STRING_substr( A0xtumlsret, (const i_t)(a - p_s), (const i_t)(b - p_s)+1, p_s ); } return A0xtumlsret; }
/* * Bridge: getword */ c_t * STRING_getword( const i_t p_i, const i_t p_j, c_t * p_s ) { c_t result[ESCHER_SYS_MAX_STRING_LEN]; result[0] = '\0'; i_t len = (i_t)Escher_strlen( p_s ); i_t lim = p_j; // if j is -1, it just means the full length of the string if ( -1 == lim ) lim = len; // check arguments if ( !(p_i < 0 || p_i > len - 1) && !(lim < 0 || lim > len) ) { c_t * w_begin; c_t * w_end; // find the first non comma, whitespace, or close parenthesis w_begin = p_s + p_i; while ( w_begin - p_s < len ) { if ( *w_begin != ',' && *w_begin != ' ' && *w_begin != '\n' && *w_begin != '\r' && *w_begin != '\t' && *w_begin != '(' && *w_begin != ')' ) break; w_begin++; } // find the first comma, whitespace, or close parenthesis after starting the word w_end = w_begin; while ( w_end - p_s < len ) { if ( *w_end == ',' || *w_end == ' ' || *w_end == '\n' || *w_end == '\r' || *w_end == '\t' || *w_end == '(' || *w_end == ')' ) break; w_end++; } if ( (w_begin - p_s) < lim && (w_end - p_s) <= lim ) { // copy the substring into the result //Escher_strcpy( result, STRING_substr( (const i_t)(w_begin - p_s), (const i_t)(w_end - p_s), p_s ) ); c_t * sub = STRING_substr( (const i_t)(w_begin - p_s), (const i_t)(w_end - p_s), p_s ); // Escher_strcpy c_t * dst = result; c_t * src = sub; if ( 0 != src ) { Escher_size_t i = Escher_strlen( src ) + 1; while ( ( i > 0 ) && ( *src != '\0' ) ) { --i; *dst++ = *src++; } *dst = '\0'; /* Ensure delimiter. */ } } } return result; }