#include #include #include "misc.h" void str3_required(){} /* Copy a character sequence delimited by a quote charater. The first character of str is taken as the quote character. Two consecutive quote character are taken as an escape mecanism to incorporate a single quote in the string. The escape character is normally '\\'. Return the address right after the closing quote. May optionnaly "compile" some C escape sequence The quote character are omitted. */ char *str_copyquotec ( char *dest, // Will contain the string inside the two delimiting // quote character. // May be NULL. Used to skip pass a sequence. int destsize, const char *str,// String beginning with a quote character (any). char escape, // Generally '\\' or '\0' if no escape defined. bool compile) // Should we translate C language special escape (such // as '\n'. { char quote = *str++; char dummy[10]; char *end = dummy+9; bool copie = true; if (dest == NULL){ dest = dummy; copie = false; }else{ end = dest + destsize; } while (*str != '\0' && dest < end){ if (!copie) dest = dummy; if (*str == quote){ str++; if (*str == quote){ if (!compile) *dest++ = quote; *dest++ = *str++; }else{ break; } }else if (*str == escape){ str++; if (compile){ char res = *str; switch (res){ case 'b': res = '\b'; break; case 'f': res = '\f'; break; case 'n': res = '\n'; break; case 'r': res = '\r'; break; case 'a': res = '\a'; break; default: if (isdigit(res)){ int base = 8; while (1){ char carac = *str; if (isdigit(carac)){ res = (char)(res * base + carac - '0'); }else if (carac == 'x' || carac == 'X'){ base = 16; }else if (isxdigit(carac) || base == 16){ res = (char)(res * base + (carac & 0xf) + 9); }else{ break; } } }else{ res = *str; } } str++; *dest++ = res; }else{ *dest++ = escape; if (*str != '\0') *dest++ = *str++; } }else{ *dest++ = *str++; } } *dest = '\0'; return (char*)str; } /* Same as above, but assume dest is 100 character long max. Kept for compatibility. Should use the above function. */ char *str_copyquotec ( char *dest, // Will contain the string inside the two delimiting // quote character. // May be NULL. Used to skip pass a sequence. const char *str,// String beginning with a quote character (any). char escape, // Generally '\\' or '\0' if no escape defined. bool compile) // Should we translate C language special escape (such // as '\n'. { return str_copyquotec (dest,100,str,escape,compile); } /* Copy a character sequence delimited by a quote charater. The first character of str is taken as the quote character. Two consecutive quote character are taken as an escape mecanism to incorporate a single quote in the string. The escape is '\\'. Return the address right after the closing quote. May optionnaly "compile" some C escape sequence The quote character are omitted. */ char *str_copyquote ( char *dest, // Will contain the string inside the quote. // May be NULL to skip a quote sequence. const char *str,// String starting with a quote character int destsize) { return str_copyquotec(dest,destsize,str,'\0',false); } char *str_copyquote ( char *dest, // Will contain the string inside the quote. // May be NULL to skip a quote sequence. const char *str)// String starting with a quote character { return str_copyquotec(dest,100,str,'\0',false); } char *str_copyquote ( SSTRING &dest, // Will contain the string inside the quote. // May be NULL to skip a quote sequence. const char *str)// String starting with a quote character { char tmp[1000]; tmp[0] = '\0'; char *ret = str_copyquotec(tmp,sizeof(tmp)-1,str,'\0',false); dest = tmp; return ret; }