static void WriteRightJustified(VSILFILE* fp, double dfValue, int nWidth, int nDecimals = -1) { char szFormat[32]; if (nDecimals >= 0) sprintf(szFormat, "%%.%df", nDecimals); else sprintf(szFormat, "%%g"); char* pszValue = (char*)CPLSPrintf(szFormat, dfValue); char* pszE = strchr(pszValue, 'e'); if (pszE) *pszE = 'E'; if ((int)strlen(pszValue) > nWidth) { sprintf(szFormat, "%%.%dg", nDecimals); pszValue = (char*)CPLSPrintf(szFormat, dfValue); pszE = strchr(pszValue, 'e'); if (pszE) *pszE = 'E'; } CPLString osValue(pszValue); WriteRightJustified(fp, osValue.c_str(), nWidth); }
static void WriteRightJustified(VSILFILE* fp, double dfValue, int nWidth, int nDecimals = -1) { char szFormat[32]; if (nDecimals >= 0) snprintf(szFormat, sizeof(szFormat), "%%.%df", nDecimals); else snprintf(szFormat, sizeof(szFormat), "%%g"); char* pszValue = const_cast<char *>( CPLSPrintf(szFormat, dfValue) ); char* pszE = strchr(pszValue, 'e'); if (pszE) *pszE = 'E'; if( static_cast<int>( strlen(pszValue) ) > nWidth) { snprintf(szFormat, sizeof(szFormat), "%%.%dg", nDecimals); pszValue = const_cast<char *>( CPLSPrintf(szFormat, dfValue) ); pszE = strchr(pszValue, 'e'); if (pszE) *pszE = 'E'; } CPLString osValue(pszValue); WriteRightJustified(fp, osValue.c_str(), nWidth); }
/** * Return the value matching a key from a key=value pair in a URL. * * @param pszURL the URL. * @param pszKey the key to find. * @return the value of empty string if not found. * @since GDAL 1.9.0 */ CPLString CPLURLGetValue(const char* pszURL, const char* pszKey) { CPLString osKey(pszKey); osKey += "="; size_t nKeyPos = CPLString(pszURL).ifind(osKey); if (nKeyPos != std::string::npos) { CPLString osValue(pszURL + nKeyPos + strlen(osKey)); const char* pszValue = osValue.c_str(); const char* pszSep = strchr(pszValue, '&'); if (pszSep) { osValue.resize(pszSep - pszValue); } return osValue; } return ""; }
static void WriteRightJustified(VSILFILE* fp, int nValue, int nWidth) { CPLString osValue(CPLSPrintf("%d", nValue)); WriteRightJustified(fp, osValue.c_str(), nWidth); }
bool GMLASXLinkResolutionConf::LoadFromXML(CPLXMLNode* psRoot) { m_nTimeOut = atoi( CPLGetXMLValue( psRoot, "Timeout", "0" ) ); m_nMaxFileSize = atoi( CPLGetXMLValue( psRoot, "MaxFileSize", CPLSPrintf("%d", MAX_FILE_SIZE_DEFAULT)) ); m_nMaxGlobalResolutionTime = atoi( CPLGetXMLValue( psRoot, "MaxGlobalResolutionTime", "0" ) ); m_osProxyServerPort = CPLGetXMLValue( psRoot, "ProxyServerPort", "" ); m_osProxyUserPassword = CPLGetXMLValue( psRoot, "ProxyUserPassword", "" ); m_osProxyAuth = CPLGetXMLValue( psRoot, "ProxyAuth", "" ); m_osCacheDirectory = CPLGetXMLValue( psRoot, "CacheDirectory", "" ); if( m_osCacheDirectory.empty() ) { m_osCacheDirectory = GMLASConfiguration::GetBaseCacheDirectory(); if( !m_osCacheDirectory.empty() ) { m_osCacheDirectory = CPLFormFilename( m_osCacheDirectory, "xlink_resolved_cache", NULL ); } } m_bDefaultResolutionEnabled = CPLGetXMLBoolValue( psRoot, "DefaultResolution.enabled", DEFAULT_RESOLUTION_ENABLED_DEFAULT); m_bDefaultAllowRemoteDownload = CPLGetXMLBoolValue( psRoot, "DefaultResolution.AllowRemoteDownload", ALLOW_REMOTE_DOWNLOAD_DEFAULT); // TODO when we support other modes // m_eDefaultResolutionMode = m_nDefaultResolutionDepth = atoi( CPLGetXMLValue( psRoot, "DefaultResolution.ResolutionDepth", "1") ); m_bDefaultCacheResults = CPLGetXMLBoolValue( psRoot, "DefaultResolution.CacheResults", CACHE_RESULTS_DEFAULT); CPLXMLNode* psIterURL = psRoot->psChild; for( ; psIterURL != NULL; psIterURL = psIterURL->psNext ) { if( psIterURL->eType == CXT_Element && strcmp(psIterURL->pszValue, "URLSpecificResolution") == 0 ) { GMLASXLinkResolutionConf::URLSpecificResolution oItem; oItem.m_osURLPrefix = CPLGetXMLValue(psIterURL, "URLPrefix", ""); oItem.m_bAllowRemoteDownload = CPLGetXMLBoolValue( psIterURL, "AllowRemoteDownload", ALLOW_REMOTE_DOWNLOAD_DEFAULT); const char* pszResolutionModel = CPLGetXMLValue(psIterURL, "ResolutionMode", "RawContent"); if( EQUAL(pszResolutionModel, "RawContent") ) oItem.m_eResolutionMode = RawContent; else oItem.m_eResolutionMode = FieldsFromXPath; oItem.m_nResolutionDepth = atoi( CPLGetXMLValue( psIterURL, "ResolutionDepth", "1") ); oItem.m_bCacheResults = CPLGetXMLBoolValue( psIterURL, "CacheResults", CACHE_RESULTS_DEFAULT); CPLXMLNode* psIter = psIterURL->psChild; for( ; psIter != NULL; psIter = psIter->psNext ) { if( psIter->eType == CXT_Element && strcmp(psIter->pszValue, "HTTPHeader") == 0 ) { CPLString osName( CPLGetXMLValue(psIter, "Name", "") ); CPLString osValue( CPLGetXMLValue(psIter, "Value", "") ); oItem.m_aosNameValueHTTPHeaders.push_back( std::pair<CPLString, CPLString>(osName, osValue)); } else if( psIter->eType == CXT_Element && strcmp(psIter->pszValue, "Field") == 0 ) { URLSpecificResolution::XPathDerivedField oField; oField.m_osName = CPLGetXMLValue(psIter, "Name", ""); oField.m_osType = CPLGetXMLValue(psIter, "Type", ""); oField.m_osXPath = CPLGetXMLValue(psIter, "XPath", ""); oItem.m_aoFields.push_back( oField ); } } m_aoURLSpecificRules.push_back( oItem ); } } return true; }