#include #include #include #include #include #include #include #include "memisc.h" void trim (char *string, int len){ int i; for(i = len-1; i >= 0; i--){ if(string[i] == 32) string[i]=0; else break; } } SEXP is_value(SEXP s_text){ PROTECT(s_text = AS_CHARACTER(s_text)); const char *text = CHAR(STRING_ELT(s_text,0)); int i, result = 1; for(i = 0; i < strlen(text); i++){ if(!result) break; result = result && isdigit(text[i]); } UNPROTECT(1); return ScalarLogical(result); } SEXP is_varname(SEXP s_text){ PROTECT(s_text = AS_CHARACTER(s_text)); const char *text = CHAR(STRING_ELT(s_text,0)); int i, result = isalpha(text[0]); for(i = 1; i < strlen(text); i++){ if(!result) break; result = result && isalnum(text[i]); } UNPROTECT(1); return ScalarLogical(result); } SEXP is_slashed_varname(SEXP s_text){ PROTECT(s_text = AS_CHARACTER(s_text)); const char *text = CHAR(STRING_ELT(s_text,0)); if(text[0] != '/'){ UNPROTECT(1); return ScalarLogical(FALSE); } text++; if(strlen(text)<1){ UNPROTECT(1); return ScalarLogical(FALSE); } int i, result = isalpha(text[0]); for(i = 1; i < strlen(text); i++){ if(!result) break; result = result && isalnum(text[i]); } UNPROTECT(1); return ScalarLogical(result); } SEXP firstnum(SEXP s_text){ PROTECT(s_text = AS_CHARACTER(s_text)); const char *text = CHAR(STRING_ELT(s_text,0)); int pos = 0; while(isdigit(text[pos])) pos++; if(text[pos] == '.') pos++; while(text[pos] == ' ') pos++; char *result = R_alloc(pos+1,1); memset(result,0,pos+1); memcpy(result,text,pos); UNPROTECT(1); return mkString(result); } #undef DEBUG SEXP is_floatspec(SEXP s_text){ PROTECT(s_text = AS_CHARACTER(s_text)); const char *text = CHAR(STRING_ELT(s_text,0)); size_t pos, sl = strlen(text); #ifdef DEBUG Rprintf("Tested string: %s\n",text); #endif if(strlen(text) < 3 || text[0]!='(' || text[sl-1] != ')'){ UNPROTECT(1); return ScalarLogical(FALSE); } for(pos=1; pos