MCPcopy Create free account
hub / github.com/TASEmulators/fceux / str_strip

Function str_strip

src/utils/xstring.cpp:115–135  ·  view source on GitHub ↗

Removes whitespace depending on the flags set (See STRIP_x definitions in xstring.h) Returns number of characters removed, or -1 on error

Source from the content-addressed store, hash-verified

113///Removes whitespace depending on the flags set (See STRIP_x definitions in xstring.h)
114///Returns number of characters removed, or -1 on error
115int str_strip(char *str, int flags) {
116 unsigned int i=0,j=0; //mbg merge 7/17/06 changed to unsigned int
117 char *astr,chr;
118
119 if (!strlen(str)) return -1;
120 if (!(flags & (STRIP_SP|STRIP_TAB|STRIP_CR|STRIP_LF))) return -1;
121 if (!(astr = (char*)malloc(strlen(str)+1))) return -1;
122 while (i < strlen(str)) {
123 chr = str[i++];
124 if ((flags & STRIP_SP) && (chr == ' ')) chr = 0;
125 if ((flags & STRIP_TAB) && (chr == '\t')) chr = 0;
126 if ((flags & STRIP_CR) && (chr == '\r')) chr = 0;
127 if ((flags & STRIP_LF) && (chr == '\n')) chr = 0;
128
129 if (chr) astr[j++] = chr;
130 }
131 astr[j] = 0;
132 strcpy(str,astr);
133 free(astr);
134 return j;
135}
136
137
138///Character replacement routine

Callers 1

AssembleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected