bool process_string(const char * src,pfc::string_base & out)//returns if changed { if (check_string(src)) {out=src;return false;} unsigned idx=0; while(src[idx]==' ') idx++; while(src[idx]) { if (is_alphanumeric(src[idx]) && !is_used(src[idx])) { insert(src,idx,out); return true; } while(src[idx] && src[idx]!=' ' && src[idx]!='\t') idx++; if (src[idx]=='\t') break; while(src[idx]==' ') idx++; } //no success picking first letter of one of words idx=0; while(src[idx]) { if (src[idx]=='\t') break; if (is_alphanumeric(src[idx]) && !is_used(src[idx])) { insert(src,idx,out); return true; } idx++; } //giving up out = src; return false; }
void sstring::encode(const char *from, size_t length) { const char *current = from; const char *eof = from + length; while (current != eof) { if (is_alphanumeric(*current)) { const char *end = current + 1; while (is_alphanumeric(*end)) { end++; } // region is [current, end) std::string lookup(current, end - current); #ifdef DEBUG std::cerr << "Looking up <" << lookup << ">" << std::endl; #endif int key; if ((key = short_map[lookup]) != 0) { // encode word, point current to next part char encoding = 0x80 | ((key - 1) & 0x3f); buf.push_back(encoding); current = end; } else if ((key = long_map[lookup]) != 0) { // encode word, point current to next part char first_byte = 0xc0 | (((key - 1) >> 8) & 0x3f); char second_byte = (key - 1) & 0xff; buf.push_back(first_byte); buf.push_back(second_byte); current = end; } else { // encode single character buf.push_back(*current); current++; } } else {
BOOL CUndoInsertDeleteString::Append( BOOL bInsertChar, TCHAR ch, int nRow, int nCol ) { BOOL bSuccess = FALSE; if ( ( nRow == m_nRow ) && CanAppend() ) { int cbText = _tcslen( m_pszText ); ASSERT( cbText ); if ( bInsertChar ) { if ( ( m_nCol + cbText ) == nCol ) { // now, only allow appending if ch is same 'kind' of text as what's in // this record. BOOL bAlpha = is_alphanumeric( ch ); BOOL bCanAppend = TRUE; for ( register int i = 0; i < cbText; i++ ) { TCHAR chText = m_pszText[ i ]; if ( bAlpha ) { if ( !is_alphanumeric( chText ) ) { bCanAppend = FALSE; } } else { if ( is_alphanumeric( chText ) ) { bCanAppend = FALSE; } } } if ( bCanAppend ) { // can append to this record m_pszText = ( LPTSTR ) realloc( m_pszText, ( cbText + 2 ) * sizeof( TCHAR ) ); m_pszText[ cbText ] = ch; m_pszText[ cbText + 1 ] = '\0'; bSuccess = TRUE; } } } } return bSuccess; }
/* Check if a line is a label, returns 1 if it is, and 0 if not */ int is_label_line(char *line) { int i; char *p, *colon; char *alphanumeric; assert(line != NULL); colon = strchr(line, ':'); /* should have a : marking the end of the label name */ if (colon == NULL) return 0; /* only characters that should come after the colon are spaces */ for (i = 1; i < strlen(colon); i++) if (!is_whitespace(colon[i])) return 0; /* and everything before it should be alphanumeric or a space or underscore */ for (p = line; p < colon; p++) if (!is_alphanumeric(*p) && !is_whitespace(*p) && *p != '_') return 0; /* ...but we cannot have a space in the middle of the label (e.g. "LA BEL:" disallowed) AND we must have atleast one alphanumeric character for the label name */ alphanumeric = get_first_alphanumeric(line); if (alphanumeric == NULL) return 0; /* from the first alphanumeric character to the : */ for (p = alphanumeric; p < colon; p++) { if (!is_alphanumeric(*p) && *p != '_') /* we should only have alphanumeric characters or underscores */ return 0; p++; } return 1; }
//[[Rcpp::export]] std::vector < bool > is_alphanumeric_vector(std::vector < std::string > strs){ return is_alphanumeric(strs); }
//[[Rcpp::export]] bool is_alphanumeric_single(std::string str){ return is_alphanumeric(str); }