--- parser3/src/main/pa_common.C 2009/04/22 04:35:48 1.243 +++ parser3/src/main/pa_common.C 2009/05/26 10:44:33 1.245 @@ -26,7 +26,7 @@ * */ -static const char * const IDENT_COMMON_C="$Date: 2009/04/22 04:35:48 $"; +static const char * const IDENT_COMMON_C="$Date: 2009/05/26 10:44:33 $"; #include "pa_common.h" #include "pa_exception.h" @@ -794,13 +794,12 @@ size_t strpos(const char *str, const cha // content-type: xxx; charset=WE-NEED-THIS // content-type: xxx; charset="WE-NEED-THIS" // content-type: xxx; charset="WE-NEED-THIS"; -Charset* detect_charset(const char* content_type){ +Charset* detect_charset(const char* content_type, bool already_uppercased){ if(content_type){ - size_t len=strlen(content_type); - char* CONTENT_TYPE=new(PointerFreeGC) char[len+1]; - memcpy(CONTENT_TYPE, content_type, len); - for(char *p=CONTENT_TYPE; *p; p++) - *p=(char)toupper((unsigned char)*p); + char* CONTENT_TYPE=pa_strdup(content_type); + if(!already_uppercased) + for(char *p=CONTENT_TYPE; *p; p++) + *p=(char)toupper((unsigned char)*p); if(const char* begin=strstr(CONTENT_TYPE, "CHARSET=")){ begin+=8; // skip "CHARSET=" @@ -813,47 +812,14 @@ Charset* detect_charset(const char* cont if(!end) end=(char*)strchr(begin, ';'); - size_t len; - if(end){ + if(end) *end=0; // terminator - len=end-begin; - } else { - len=strlen(begin); - } - String::Body NAME=String::Body(begin, len); - return &charsets.get(NAME); + return *begin?&charsets.get(begin):0; } } return 0; } - -Charset* detect_charset(Charset& source_charset, const String& content_type){ - const String& CONTENT_TYPE=content_type.change_case(source_charset, String::CC_UPPER); - size_t begin=CONTENT_TYPE.pos("CHARSET="); - if(begin!=STRING_NOT_FOUND) { - begin+=8; // skip "CHARSET=" - size_t end=STRING_NOT_FOUND; - - if(CONTENT_TYPE.pos('"', begin)==begin){ - begin++; - end=CONTENT_TYPE.pos('"', begin); - } else if(CONTENT_TYPE.pos('\'', begin)==begin){ - begin++; - end=CONTENT_TYPE.pos('\'', begin); - } - - if(end==STRING_NOT_FOUND) - end=CONTENT_TYPE.pos(';', begin); - - if(end==STRING_NOT_FOUND) - end=CONTENT_TYPE.length(); - - const String::Body NAME=CONTENT_TYPE.mid(begin, end); - return &charsets.get(NAME); - } - return 0; -} static bool isLeap(int year) {