void String::split(UChar separator, bool allowEmptyEntries, Vector<String>& result) const { result.clear(); int startPos = 0; int endPos; while ((endPos = find(separator, startPos)) != -1) { if (allowEmptyEntries || startPos != endPos) result.append(substring(startPos, endPos - startPos)); startPos = endPos + 1; } if (allowEmptyEntries || startPos != static_cast<int>(length())) result.append(substring(startPos)); }
void String::split(UChar separator, bool allowEmptyEntries, Vector<String>& result) const { result.clear(); unsigned startPos = 0; size_t endPos; while ((endPos = find(separator, startPos)) != kNotFound) { if (allowEmptyEntries || startPos != endPos) result.append(substring(startPos, endPos - startPos)); startPos = endPos + 1; } if (allowEmptyEntries || startPos != length()) result.append(substring(startPos)); }
static int decode_line_directive (const char* line) { uintL n = strlen(line); uintL i = 0; /* Skip whitespace. */ for (; i < n && is_whitespace(line[i]); i++) {} /* Parse a '#'. */ if (i < n && line[i] == '#') i++; else return -1; /* Skip whitespace. */ for (; i < n && is_whitespace(line[i]); i++) {} /* Check for "line". */ if (i+4 < n && line[i+0] == 'l' && line[i+1] == 'i' && line[i+2] == 'n' && line[i+3] == 'e' && is_whitespace(line[i+4])) { i += 4; for (; i < n && is_whitespace(line[i]); i++) {} } /* Check for a digit. */ if (!(i < n && is_digit(line[i]))) return -1; { uintL i1 = i; for (; i < n && is_digit(line[i]); i++) {} { uintL i2 = i; /* Convert digit string to a `long'. */ char* digits = substring(line,i1,i2); errno = 0; { long result = strtol(digits,NULL,10); xfree(digits); if (errno != 0) return -1; if (result < 0) abort(); /* Check for a source file name. */ for (; i < n && is_whitespace(line[i]); i++) {} if (i < n && line[i] == '"') { uintL i3; i++; i3 = i; for (; i < n && line[i] != '"'; i++) {} if (i < n && line[i] == '"') { uintL i4 = i; input_filename = substring(line,i3,i4); } } return result; } } } }
void XonoticPlayerModelSelector_configureXonoticPlayerModelSelector(entity me) { float sortbuf, glob, i; string fn; glob = search_begin(language_filename(get_model_datafilename(string_null, -1, "txt")), TRUE, TRUE); if (glob < 0) return; me.configureXonoticImage(me, string_null, -1); sortbuf = buf_create(); for(i = 0; i < search_getsize(glob); ++i) { // select model #i! fn = search_getfilename(glob, i); if(!get_model_parameters(fn, -1)) continue; bufstr_add(sortbuf, sprintf("%-128s%s", get_model_parameters_name, fn), 1); } search_end(glob); buf_sort(sortbuf, 128, 0); me.numModels = buf_getsize(sortbuf); me.bufModels = buf_create(); for(i = 0; i < me.numModels; ++i) { fn = substring(bufstr_get(sortbuf, i), 128, -1); if(!get_model_parameters(fn, -1)) error("But it JUST worked!"); bufstr_set(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_TITLE, get_model_parameters_name); bufstr_set(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_IMAGE, strcat("/", substring(get_model_datafilename(get_model_parameters_modelname, get_model_parameters_modelskin, "tga"), 0, -5))); bufstr_set(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_MODEL, get_model_parameters_modelname); bufstr_set(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_SKIN, ftos(get_model_parameters_modelskin)); get_model_parameters_desc = strcat(get_model_parameters_desc, "\n"); if(get_model_parameters_sex) get_model_parameters_desc = strcat(get_model_parameters_desc, sprintf("\nSex: %s", get_model_parameters_sex)); if(get_model_parameters_weight) get_model_parameters_desc = strcat(get_model_parameters_desc, sprintf("\nWeight: %g kg", get_model_parameters_weight)); if(get_model_parameters_age) get_model_parameters_desc = strcat(get_model_parameters_desc, sprintf("\nAge: %g", get_model_parameters_age)); while(substring(get_model_parameters_desc, -1, 1) == "\n") get_model_parameters_desc = substring(get_model_parameters_desc, 0, -2); bufstr_set(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_DESC, get_model_parameters_desc); } buf_del(sortbuf); get_model_parameters(string_null, 0); me.loadCvars(me); // this will select the initial model, depending on the current cvars me.go(me, 0); // this will set the vars for the selected model }
/* extract a specified directory path given the level NOTE: the level can be positive or negative */ char* extractDirectory(char* path, int level) { /* length of path string */ int length = strlen(path); /* current directory level */ int currentLevel = 0; /* used to store directory separator index */ int targetDirectorySeparatorIndex = 0; /* iterator */ int i; /* iterate through the directory levels */ for (i=0; i<abs(level); i++) { /* negative level */ if (level < 0) { targetDirectorySeparatorIndex = lastIndexOf(path,'\\'); path = substring(path, 0, targetDirectorySeparatorIndex); } /* positive level */ else { /* first iteration - special case */ if (targetDirectorySeparatorIndex == 0) { targetDirectorySeparatorIndex = indexOfWithStart(path,'\\', targetDirectorySeparatorIndex); } /* all other iterations - must add 1*/ else { targetDirectorySeparatorIndex = indexOfWithStart(path,'\\', targetDirectorySeparatorIndex + 1); } } } /* if a positive level, must extract the directory string now */ if (level > 0) { path = substring(path, 0, targetDirectorySeparatorIndex); } return path; }
void ToggleFavorite(string srv) { string s, s0, s1, s2, srv_resolved, p; float i, n, f; srv_resolved = netaddress_resolve(srv, 26000); p = crypto_getidfp(srv_resolved); s = cvar_string("net_slist_favorites"); n = tokenize_console(s); f = 0; for(i = 0; i < n; ++i) { if(substring(argv(i), 0, 1) != "[" && strlen(argv(i)) == 44 && strstrofs(argv(i), ".", 0) < 0) { if(p) if(argv(i) != p) continue; } else { if(srv_resolved != netaddress_resolve(argv(i), 26000)) continue; } s0 = s1 = s2 = ""; if(i > 0) s0 = substring(s, 0, argv_end_index(i - 1)); if(i < n-1) s2 = substring(s, argv_start_index(i + 1), -1); if(s0 != "" && s2 != "") s1 = " "; cvar_set("net_slist_favorites", strcat(s0, s1, s2)); s = cvar_string("net_slist_favorites"); n = tokenize_console(s); f = 1; --i; } if(!f) { s1 = ""; if(s != "") s1 = " "; if(p) cvar_set("net_slist_favorites", strcat(s, s1, p)); else cvar_set("net_slist_favorites", strcat(s, s1, srv)); } resorthostcache(); }
int Ibelium::readSMS(sms* msg) { //Reads the most recent SMS and deletes it /*Message Format: (reference for string parsing) +CMGL:<index>,<stat>,<number>,<unknown>,<timestamp><CR><LF> <data> <index> = the index in memory of the message <stat> = status of the message, either REC UNREAD, REC READ, STO UNSENT, STO UNREAD. We only want to read ones that are REC, not STO. <number> = Where the message came from <unknown> = seems to be empty <timestamp> = "yy/mm/dd, hh:mm:ss-20" */ free(msg->number); //Make sure response is a NULL pointer. free(msg->message); free(msg->dateTime); int index=0; char* resp; int i = sendATQuery("AT+CMGL=\"ALL\"", resp); if(i!=0) { //Command successfully sent/received //First, find the message index to allow for deletion afterwards int j=0; int k=0; while(resp[j]!=':') j++; index = atoi(&(resp[j+1]));//This number should indicate the index of the message in memory msg->index = index; //Second, copy the originating number into the structure. while(resp[j]!=',') j++; while(resp[j]!=',') j++; j+=2; msg->number = substring(resp, j, j+11); //Should copy the number to the struct. //Thirdly, copy the datestring from the message. while(resp[j]!=',') j++; while(resp[j]!=',') j++; j+=2; k=j; while(resp[k+1]!='"') k++; msg->dateTime = substring(resp, j, k); //Lastly, copy the message into the message structure while(resp[j]!='\x0A') j++; j++; //j indexes the beginning of the message; k = j;//k should index the end of the message; while(resp[k+1]!='O'&& resp[k+2]!='K') k++; msg->message = substring(resp, j, k); } return i; }
char *replace(char *text, char *from, char *to){ //if (DEBUG==1) putlog("replacing"); char *ret=(char*)calloc( strlen(text)+(strlen(to)-strlen(from)),sizeof(char)); char *left; char *right; int pos=inStr(text,strlen(text),from); if (pos!=-1){ left=substring(text,0,pos); right=substring(text,pos+strlen(from),strlen(text)-(pos+strlen(from))); ret=str3cat(left,to,right); return replace(ret,from,to); } //if (DEBUG==1) putlog("replaced"); return text; }
string remove_suffix (string s) { string suffix = find_suffix (s); return suffix == NULL ? xstrdup (s) : substring (s, 0, suffix - 2 - s); }
inline bool skip_accept(Scanner *s, String str) { // The string is invalid if (str.length == 0) return false; const char *pos = s->pos; const char *end = s->end; // The string doesn't fit into what's left to scan if ((size_t)(end - pos) < str.length) return false; char first = str.data[0]; for (; pos != end; pos++) { if (*pos != first) continue; String suffix = substring(str, 1); if (!memcmp(pos + 1, suffix.data, suffix.length)) { s->pos = pos + str.length; return true; } } return false; }
int* findSubstring(char* s, char** words, int wordsSize, int* returnSize) { int lenw=strlen(words[0]),lens=strlen(s),length=wordsSize; int* res=(int*)malloc(sizeof(int)*(lens-lenw*length+1)); data** map=(data**)malloc(sizeof(data*)*SIZE); data** tmp=(data**)malloc(sizeof(data*)*SIZE); int i,j; for(i=0;i<SIZE;i++){ map[i]=NULL; tmp[i]=NULL; } for(i=0;i<length;i++){ InsertMap(map,words[i],lenw); } *returnSize=0; for(i=0;i<lens-lenw*length+1;i++){ for(j=0;j<SIZE;j++){ if(tmp[j]!=NULL){ free(tmp[j]); tmp[j]=NULL; } } for(j=0;j<length;j++){ char* sub=substring(s,i+j*lenw,lenw); int mapnum=FindMap(map,sub); if(mapnum==-1)break; int num=InsertMap(tmp,sub,lenw); if(mapnum < num)break; free(sub); } if(j>=length)res[(*returnSize)++]=i; } for(i=0;i<SIZE;i++)if(map[i]!=NULL)free(map[i]); free(map); return res; }
void complete_token() { switch(token->type) { case TTYPE_IDENT_OR_RESERV: if(token->type == TTYPE_IDENT_OR_RESERV) { int index_of_reserved = search_reserved_words_table(token->lexeme); if (index_of_reserved != INDEX_NOT_FOUND) { token->type = TTYPE_RESERVED_WORD; token->value = index_of_reserved; } else { token->type = TTYPE_IDENTIFIER; token->value = add_if_new_identifiers_table(token->lexeme); } } break; case TTYPE_SPECIAL_CHARACTER: token->value = search_special_characters_table(token->lexeme); break; case TTYPE_NUM: token->value = atoi(token->lexeme); break; case TTYPE_STRING: token->lexeme = substring(token->lexeme, 1, strlen(token->lexeme)-2); break; default: /* Other types do not have token->value */ break; } }
string expandPathname(string filename) { string homedir; char *spos; struct passwd *pw; if (*filename == '~') { spos = filename; while ((*spos != '/') && (*spos != '\\') && (*spos != '\0')) { spos++; } if (spos - filename == 1) { homedir = getenv("HOME"); if (homedir == NULL) { error("expandPathname: No HOME environment variable"); } } else { homedir = substring(filename, 1, spos - filename - 1); homedir = concat("\\Users\\", homedir); } filename = concat(homedir, spos); } else { filename = copyString(filename); } for (spos = filename; *spos != '\0'; spos++) { if (*spos == '/') *spos = '\\'; } return filename; }
static String_buf read_mace4_input(FILE *fp) { char line[1000], *s; /* the first 999 chars of the line */ String_buf sb = get_string_buf(); BOOL ok = FALSE; s = fgets(line, 1000, fp); while (s && !substring("==== end of input", s)) { if (!ok && (initial_substring("clauses(", s) || initial_substring("formulas(", s))) { if (sb_size(sb) != 0) sb_append(sb, "\n"); /* no newline before first list */ ok = TRUE; } if (ok) { sb_append(sb, s); if (initial_substring("end_of_list.", s)) ok = FALSE; } s = fgets(line, 1000, fp); } if (!s) fatal_error("read_mace4_input, \"==== end of input\" not found"); return sb; } /* read_mace4_input */
string getHead(string pathname) { register char *cp; char *slashpos; slashpos = NULL; for (cp = pathname; *cp; cp++) { if (*cp == '/' || *cp == '\\') slashpos = cp; } if (slashpos == NULL) { return ""; } else if (slashpos == pathname) { return substring(pathname, 0, 0); } else { return substring(pathname, 0, (slashpos - pathname) - 1); } }
string NexuizDemoList_demoName(entity me, float i ) { string s; s = search_getfilename(me.listDemo, i); s = substring(s, 6, strlen(s) - 6 - 4); // demos/, .dem return s; }
string getParentDirectory(const string path) { int start = 0; int end = path.size() - 1; if (path[end] == '/') { end--; } bool found = false; while (end >= 0) { if (path[end--] == '/') { found = true; break; } } if (found) { return substring(path, 0, end + 1); } return "."; }
Vector<String> String::split(const String& separator, bool allowEmptyEntries) const { Vector<String> result; int startPos = 0; int endPos; while ((endPos = find(separator, startPos)) != -1) { if (allowEmptyEntries || startPos != endPos) result.append(substring(startPos, endPos - startPos)); startPos = endPos + separator.length(); } if (allowEmptyEntries || startPos != (int)length()) result.append(substring(startPos)); return result; }
static FmtArray *add_fmt(FmtArray *f, const char *fmt, const char **end_pos) { int lalign=0, strip=0, failed=0; unsigned long long width=0; const char *pos=fmt; if(!fmt) return f; if(*pos=='%') pos++; /* check for cvt_spec with no options */ if (strchr(no_nparam,*pos)) { if(end_pos) *end_pos=pos+1; return FmtArray_add(f,FmtInfo_new(*pos,0,0,0,0,0)); } /* check for flags */ /* in a reverse from printf style, %0x *removes* zeros, not pads them */ for(;*pos&& (*pos=='-' || *pos=='0');pos++) { if(!lalign) lalign=*pos=='-'; if(!strip) strip=*pos=='0'; } width=strtoull(pos,(char **)&pos,10); failed=!strchr(has_nfld, *pos) || !*pos; if(end_pos) *end_pos=pos+1; return FmtArray_add(f,FmtInfo_new(*pos,strip,lalign,width,failed, failed ? substring(fmt,pos+1) : 0)); }
int main() { /* MemStat memStat("main"); */ for(int i = 0; i < 1; i++) { input(); copy(); find2(); substring(); find(); replace(); remove(); insert(); compare(); plus(); append(); assign(); reserve(); constuctors(); test1(); // error(); // overflow(); } return 0; }
sp<ArrayList<sp<String>>> String::split(const char* separator) const { sp<ArrayList<sp<String>>> strings = new ArrayList<sp<String>>(); ssize_t curIndex = 0; ssize_t prevCurIndex; while (curIndex >= 0 && (size_t) curIndex < length()) { prevCurIndex = curIndex; curIndex = indexOf(separator, curIndex); if (curIndex >= 0) { strings->add(substring(prevCurIndex, curIndex)); curIndex += strlen(separator); } else { strings->add(substring(prevCurIndex, length())); } } return strings; }
XalanDOMString& GetXSLFileName(const XalanDOMString& theXMLFileName, XalanDOMString& theResult) { int thePeriodIndex = -1; const int theLength = length(theXMLFileName); for (int i = theLength - 1; i > 0; i--) { if (charAt(theXMLFileName, i) == XalanUnicode::charFullStop) { thePeriodIndex = i; break; } } if (thePeriodIndex != -1) { substring(theXMLFileName, theResult, 0, thePeriodIndex + 1); theResult.append("xsl"); } return theResult; }
float IsFavorite(string srv) { string p; float i, n; if(srv == "") return FALSE; srv = netaddress_resolve(srv, 26000); if(srv == "") return FALSE; p = crypto_getidfp(srv); n = tokenize_console(cvar_string("net_slist_favorites")); for(i = 0; i < n; ++i) { if(substring(argv(i), 0, 1) != "[" && strlen(argv(i)) == 44 && strstrofs(argv(i), ".", 0) < 0) { if(p) if(argv(i) == p) return TRUE; } else { if(srv == netaddress_resolve(argv(i), 26000)) return TRUE; } } return FALSE; }
char *strip(const char* input) { if (!input) { return NULL; } size_t str_len = strlen(input); if (str_len < 1) { return NULL; } int beg = 0; while (beg < str_len) { if (input[beg] == ' ' || input[beg] == '\t' || input[beg] == '\n') ++beg; else break; } int end = str_len-1; while (end > 0) { if (input[end] == ' ' || input[end] == '\t' || input[end] == '\n') --end; else break; } long len = end - beg + 1; if (len < 1) { fprintf(stderr, "sgen: strip: input string len < 1!\n"); return NULL; } char *r = substring(input, beg, len); return r; }
const char *relativeFilePath(const char *rel, const char *file) { if(file[0] == '/') return file; char *rslash, *dir, *ret; char fn[MAX_FN_LEN]; char buff[MAX_FN_LEN]; if((rslash = strrchr(rel, '/')) != NULL) { strncpy(buff, file, MAX_FN_LEN); dir = substring(rel, 0, strlen(rel) - strlen(rslash)); makeabspath_wd(fn, buff, dir, MAX_FN_LEN); fn[strlen(fn)] = '\0'; ret = strdup(fn); //ds_printf("Directory: '%s' File: '%s' Out: '%s'", dir, rslash, ret, fn); free(dir); } else { return file; } return ret; }
char* match_group(match_t* match, int gr) { assert(match); group_t* captcha = range_group(match->groups, gr); if (!captcha || !captcha->begin) return NULL; return substring(captcha->begin, captcha->end); }
bool _NativeFrameworkDSString::endWith(string cppString){ // the last of the string equals to tge string passed to check string thisEndString = substring(length()-cppString.length(), length()); if(cppString == thisEndString) return true; return false; }
/** * parses the -t/--time option for a timed * interval. The option requires a modifier, * H, M, or S, hours, minutes or seconds */ void parse_time(char *p) { size_t x = 0; my.time = my.secs = 0; while(ISDIGIT(p[x])) x++; if (x==0) return; my.time = atoi(substring(p, 0, x)); for(; x < strlen(p); x ++) switch(TOLOWER(p[x])){ case 's': my.secs = my.time; my.time = 1; return; case 'm': my.secs = my.time * 60; my.time = 1; return; case 'h': my.secs = my.time * 3600; my.time = 1; return; default: break; } if((my.time > 0) && (my.secs <= 0)){ my.secs = my.time * 60; } return; }
int main(){ int i=0,j=0; int tmp=0; char* p = "acbac"; char* t = "acaccbabb"; char* tmpStr =NULL; int plen = strlen(p); //i:表示截取字符串的次数 for (i=plen;i>0;i--) { tmp=plen-i+1; //j表示截取和KMP匹配的次数 for (j=0;j<tmp;j++) { tmpStr=substring(p,j,i); getpos=-1; kmp_match(t,tmpStr); if (getpos!=-1) { //输出结果,并退出程序 printf("result:%d\n",i); i=0; break; } free(tmpStr); } } return 0; }
static const char* is_elif (const char* line) { uintL n = strlen(line); uintL i = 0; /* Skip whitespace. */ for (; i < n && is_whitespace(line[i]); i++) {} /* Parse a '#'. */ if (i < n && line[i] == '#') i++; else return NULL; /* Skip whitespace. */ for (; i < n && is_whitespace(line[i]); i++) {} /* Check for "elif". */ if (i+4 < n && line[i+0] == 'e' && line[i+1] == 'l' && line[i+2] == 'i' && line[i+3] == 'f' && is_whitespace(line[i+4])) { i += 5; for (; i < n && is_whitespace(line[i]); i++) {} for (; n > i && is_whitespace(line[n-1]); n--) {} return substring(line,i,n); } return NULL; }