bool String::Divide(StringVector& sv, bool bDQM) { static char Blanks[NUM_BLANKS] = {' ', '\t', '\r', '\n', '\0'}; sv.clear(); bool bEnterDQM = false; // double quotation marks Common::String sTemp; for(unsigned int i = 0; i < GetSize(); ++i) { char c = at(i); bool bPush = false; if(bEnterDQM && bDQM) // 如果是在双引号中 { if(c == '"') // 终结双引号 { bPush = true; bEnterDQM = false; } else { sTemp += c; // 直接追加字符串 } } else // 不在双引号中 { if(c == '"' && bDQM) // 要进入双引号中 { bPush = true; bEnterDQM = true; } else // 不是双引号,只是普通字符 { bool bBlank = false; for(unsigned int j = 0; j < NUM_BLANKS; ++j) { if(c == Blanks[j]) { bPush = true; bBlank = true; // 是空白字符 break; } } if(!bBlank) // 不是空白字符 { sTemp += c; } } } if(bPush) { if(!sTemp.empty()) { sv.push_back(sTemp); sTemp.Clear(); } } } if(bEnterDQM && bDQM) // 还在双引号中,一定是出现了语法错误(漏了结束双引号) { //throw Common::Exception(Common::EL_GENERAL, "Extractor::DivideString", "Grammar error: a terminator of DQM expected!"); } if(!sTemp.empty()) { sv.push_back(sTemp); sTemp.Clear(); } return true; }