void OutputRoadName(char *pMifName, char *pMidName, vector<ST_ROADNAME> &vecRoadName) { FILE * pPointMifOut = fopen(pMifName,"wb+"); FILE * pPointMidOut = fopen(pMidName,"wb+"); if (pMifName == NULL || pPointMidOut == NULL) { return; } fprintf(pPointMifOut,"Version 300"); fprintf(pPointMifOut,"Charset \"WindowsSimpChinese\"\r\n"); fprintf(pPointMifOut,"Delimiter \",\"\r\n"); fprintf(pPointMifOut,"CoordSys Earth Projection 1, 0\r\n"); fprintf(pPointMifOut,"Columns 1\r\n"); fprintf(pPointMifOut,"Name Char(64)\r\n"); fprintf(pPointMifOut,"Data\r\n"); //输出 int mergyStart = 0; int mergyEnd = 0; int Len = vecRoadName.size(); for(int i = 1; i < Len; ++i) { if(i != (Len - 1)) { if( vecRoadName[i].iLineIndex == vecRoadName[mergyStart].iLineIndex) { mergyEnd = i; continue; } } else { mergyEnd = i; // the laset one } wstring wstr; fprintf(pPointMifOut,"Pline %d\r\n", (mergyEnd - mergyStart + 1)); for(int j = mergyStart; j <= mergyEnd; ++j) { fprintf(pPointMifOut,"%0.6f %0.6f\r\n", vecRoadName[j].dX, vecRoadName[j].dY); wstr += vecRoadName[j].wcText; } fprintf(pPointMifOut," Pen (1,2,0)"); string str = EncodeUtf8(wstr); fprintf(pPointMidOut, "\"%s\"\r\n", str.c_str()); mergyEnd = i; mergyStart = i; // reset } fclose(pPointMifOut); fclose(pPointMidOut); }
// This function is adapted from RapidJason (https://github.com/miloyip/rapidjson) void JsonReader::ParseStringToStream(Stream& os) { log_trace(); #define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 static const char escape[256] = { Z16, Z16, 0, 0,'\"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'/', Z16, Z16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'\\', 0, 0, 0, 0, 0,'\b', 0, 0, 0,'\f', 0, 0, 0, 0, 0, 0, 0,'\n', 0, 0, 0,'\r', 0,'\t', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16 }; #undef Z16 while (true) { char c = is_.Peek(); if (c == '\\') // Escape { is_.Get(); unsigned char e = is_.Get(); if (escape[e]) { os.Put(escape[e]); } else if (e == 'u') // Unicode { unsigned codepoint = ParseHex4(); if ((codepoint >= 0xD800) && (codepoint <= 0xDBff)) { // Handle as UTF-16 surrogate pair if ((is_.Get() != '\\') || (is_.Get() != 'u')) anyrpc_throw(AnyRpcErrorStringUnicodeSurrogateInvalid, "The surrogate pair in string is invalid"); unsigned codepoint2 = ParseHex4(); if ((codepoint2 < 0xDC00) || (codepoint2 > 0xDFFF)) anyrpc_throw(AnyRpcErrorStringUnicodeSurrogateInvalid, "The surrogate pair in string is invalid"); codepoint = (((codepoint - 0xD800) << 10) | (codepoint2 - 0xDC00)) + 0x10000; } EncodeUtf8(os,codepoint); } else anyrpc_throw(AnyRpcErrorStringEscapeInvalid, "Invalid escape character in string"); } else if (c == '"') // Closing double quote { is_.Get(); os.Put('\0'); // null-terminate the string return; } else if (c == '\0') anyrpc_throw(AnyRpcErrorStringMissingQuotationMark, "Missing a closing quotation mark in string"); else if ((unsigned)c < 0x20) // RFC 4627: unescaped = %x20-21 / %x23-5B / %x5D-10FFFF anyrpc_throw(AnyRpcErrorStringEscapeInvalid, "Invalid escape character in string"); else os.Put( is_.Get() ); } }