void MgWmsLayerDefinitions::GenerateDefinitions(MgUtilDictionary& Dictionary) { MgXmlSynchronizeOnElement ResourceDocument(*m_xmlParser,_("ResourceDocument")); if(!ResourceDocument.AtBegin()) return; // Something is wrong. We leave. while(!ResourceDocument.AtEnd()) { STRING sValue; // basic_string if(GetElementContents(_("ResourceId"),sValue)) { // Okay, the ResourceId is too decorated for our purposes; // the outside world doesn't need to know (and clutter up // URL command lines with) this syntactic "punctuation" so // we just get rid of it. // Remove the Library prefix, if present. if(sValue.find(_("Library://")) == 0) sValue = sValue.substr(10); // Remove the LayerDefinition suffix, if present. STRING::size_type iEnd = sValue.find(_(".LayerDefinition")); if(iEnd != STRING::npos) sValue.resize(iEnd); // There, that's our Layer Name. Dictionary.AddDefinition(_("Layer.Name"),sValue); // Until we have "Friendly Name" support, the // friendly name will simply be the layer name sans // path. iEnd = sValue.find_last_of('/'); if(iEnd != STRING::npos) sValue = sValue.substr(iEnd+1); // one past the slash. // That's our Layer Title, // Note that subsequently-found metadata may override this // definition with a real title... one that the user actually // wants. This just provides a default in case no such // friendly name exists.... that keeps the list of layer names // from being a list of empty strings. Dictionary.AddDefinition(_("Layer.Title"),sValue); } else if(!GetMetadataDefinitions(Dictionary)) { SkipElement(NULL); } } }
static void fgets(STRING & s, FILE * f) { s.resize(0); char c; while (fgetc(c, f)) { if (c == '\n' || c == '\r') { if (c == '\r' && (!fgetc(c, f) || c != '\n')) RuntimeError("fgets: malformed text file, CR without LF"); break; } s.push_back(c); // strip Unicode BOM // We strip it from any string, not just at the start. // This allows to UNIX-'cat' multiple UTF-8 files with BOMs. // Since the BOM is otherwise invalid within a file, this is well-defined and upwards compatible. if (s.size() == 3 && BeginsWithUnicodeBOM(s.c_str())) s.clear(); } }
BOOL DoParseFile(LPVOID pvContents, DWORD dwSize) { ITEMVECTOR Items; LPWSTR pch, pchSep, pchStart = (LPWSTR)pvContents; pchStart[dwSize / sizeof(WCHAR)] = UNICODE_NULL; // check header const DWORD cbHeader = lstrlenW(g_pszFileHeader) * sizeof(WCHAR); if (memcmp(pchStart, g_pszFileHeader, cbHeader) != 0) return FALSE; pchStart += cbHeader / sizeof(WCHAR); // find the key WCHAR szKey[MAX_STRING]; wsprintfW(szKey, L"[HKEY_LOCAL_MACHINE\\%s]", g_pszKey); pch = wcsstr(pchStart, szKey); if (pch == NULL) return FALSE; pchStart = pch + lstrlenW(szKey); for (;;) { pchStart = SkipSpace(pchStart); if (*pchStart == UNICODE_NULL || *pchStart == L'[') break; pch = wcschr(pchStart, L'\n'); if (pch) *pch = UNICODE_NULL; pchSep = SkipQuoted(pchStart); if (*pchSep == L'=') { *pchSep = UNICODE_NULL; STRING key = pchStart; trim(key); key = Unquote(key); STRING value = pchSep + 1; trim(value); value = Unquote(value); BYTE CharSet1 = DEFAULT_CHARSET, CharSet2 = DEFAULT_CHARSET; size_t pos; pos = key.find(L','); if (pos != STRING::npos) { CharSet1 = (BYTE)_wtoi(&key[pos + 1]); key.resize(pos); trim(key); } pos = value.find(L','); if (pos != STRING::npos) { CharSet2 = (BYTE)_wtoi(&value[pos + 1]); value.resize(pos); trim(value); } ITEM Item(key, value, CharSet1, CharSet2); Items.push_back(Item); } if (pch == NULL) break; pchStart = pch + 1; } g_Items = Items; g_bModified = TRUE; LV_AddItems(g_hListView); return TRUE; }
void DIR_LIB_SOURCE::ReadPart( STRING* aResult, const STRING& aPartName, const STRING& aRev ) throw( IO_ERROR ) { STRING partName = aPartName; const char* hasRev = endsWithRev( partName ); if( useVersioning ) { if( aRev.size() ) { // a supplied rev replaces any in aPartName if( hasRev ) partName.resize( hasRev - partName.c_str() - 1 ); partName += '/'; partName + aRev; // find this exact revision PN_ITER it = partnames.find( partName ); if( it == partnames.end() ) // part not found { partName += " not found."; THROW_IO_ERROR( partName ); } readString( aResult, makeFileName( partName ) ); } else { // There's no rev on partName string. Find the most recent rev, i.e. highest, // which will be first because of the BY_REV compare method, which treats // higher numbered revs as first. STRING search = partName + '/'; // There's no rev on partName string. Find the most recent rev, i.e. highest, // which will be first because of the BY_REV compare method, which treats // higher numbered revs as first. PN_ITER it = partnames.upper_bound( search ); // verify that this one that is greater than partName is a match and not // some unrelated name that is larger. if( it == partnames.end() || it->compare( 0, search.size(), search ) != 0 ) { partName += " is not present without a revision."; THROW_IO_ERROR( partName ); } readString( aResult, makeFileName( *it ) ); } } else // !useVersioning { #if 1 if( hasRev || aRev.size() ) { STRING msg = "this type 'dir' LIB_SOURCE not using 'useVersioning' option, cannot ask for a revision"; THROW_IO_ERROR( msg ); } #else // no revisions allowed, strip it if( hasRev ) partName.resize( hasRev - partName.c_str() - 1 ); #endif // find the part name without any revision PN_ITER it = partnames.find( partName ); if( it == partnames.end() ) // part not found { partName += " not found."; THROW_IO_ERROR( partName ); } readString( aResult, makeFileName( partName ) ); } }