本文整理汇总了C++中CPLString::assign方法的典型用法代码示例。如果您正苦于以下问题:C++ CPLString::assign方法的具体用法?C++ CPLString::assign怎么用?C++ CPLString::assign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CPLString
的用法示例。
在下文中一共展示了CPLString::assign方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetMetadataItem
void NTv2Dataset::CaptureMetadataItem( char *pszItem )
{
CPLString osKey;
CPLString osValue;
osKey.assign( pszItem, 8 );
osValue.assign( pszItem+8, 8 );
SetMetadataItem( osKey.Trim(), osValue.Trim() );
}
示例2: ReadInteger
const char *RDataset::ReadString()
{
if( ReadInteger() % 256 != R_CHARSXP )
{
osLastStringRead = "";
return "";
}
size_t nLen = ReadInteger();
char *pachWrkBuf = (char *) VSIMalloc(nLen);
if (pachWrkBuf == NULL)
{
osLastStringRead = "";
return "";
}
if( VSIFReadL( pachWrkBuf, 1, nLen, fp ) != nLen )
{
osLastStringRead = "";
CPLFree( pachWrkBuf );
return "";
}
if( bASCII )
{
/* suck up newline and any extra junk */
ASCIIFGets();
}
osLastStringRead.assign( pachWrkBuf, nLen );
CPLFree( pachWrkBuf );
return osLastStringRead;
}
示例3: WriteSelf
int ERSHdrNode::WriteSelf( VSILFILE * fp, int nIndent )
{
CPLString oIndent;
oIndent.assign( nIndent, '\t' );
for( int i = 0; i < nItemCount; i++ )
{
if( papszItemValue[i] != nullptr )
{
if( VSIFPrintfL( fp, "%s%s\t= %s\n",
oIndent.c_str(),
papszItemName[i],
papszItemValue[i] ) < 1 )
return FALSE;
}
else
{
VSIFPrintfL( fp, "%s%s Begin\n",
oIndent.c_str(), papszItemName[i] );
if( !papoItemChild[i]->WriteSelf( fp, nIndent+1 ) )
return FALSE;
if( VSIFPrintfL( fp, "%s%s End\n",
oIndent.c_str(), papszItemName[i] ) < 1 )
return FALSE;
}
}
return TRUE;
}
示例4: CSLTokenizeString
std::vector<double>
OGRDXFWriterLayer::PrepareLineTypeDefinition( OGRStylePen *poPen )
{
/* -------------------------------------------------------------------- */
/* Fetch pattern. */
/* -------------------------------------------------------------------- */
GBool bDefault;
const char *pszPattern = poPen->Pattern( bDefault );
if( bDefault || strlen(pszPattern) == 0 )
return std::vector<double>();
/* -------------------------------------------------------------------- */
/* Split into pen up / pen down bits. */
/* -------------------------------------------------------------------- */
char **papszTokens = CSLTokenizeString(pszPattern);
std::vector<double> adfWeightTokens;
for( int i = 0; papszTokens != nullptr && papszTokens[i] != nullptr; i++ )
{
const char *pszToken = papszTokens[i];
CPLString osAmount;
CPLString osDXFEntry;
// Split amount and unit.
const char *pszUnit = pszToken; // Used after for.
for( ;
strchr( "0123456789.", *pszUnit) != nullptr;
pszUnit++ ) {}
osAmount.assign(pszToken,(int) (pszUnit-pszToken));
// If the unit is other than 'g' we really should be trying to
// do some type of transformation - but what to do? Pretty hard.
// Even entries are "pen down" represented as positive in DXF.
// "Pen up" entries (gaps) are represented as negative.
if( i%2 == 0 )
adfWeightTokens.push_back( CPLAtof( osAmount ) );
else
adfWeightTokens.push_back( -CPLAtof( osAmount ) );
}
CSLDestroy( papszTokens );
return adfWeightTokens;
}
示例5: AddRelation
void OGRNASRelationLayer::AddRelation( const char *pszFromID,
const char *pszType,
const char *pszToID )
{
int nMergedLen = strlen(pszFromID) + strlen(pszType) + strlen(pszToID) + 3;
char *pszMerged = (char *) CPLMalloc(nMergedLen);
strcpy( pszMerged, pszFromID );
strcpy( pszMerged + strlen(pszFromID) + 1, pszType );
strcpy( pszMerged + strlen(pszFromID) + strlen(pszType) + 2, pszToID );
CPLString osRelation;
osRelation.assign( pszMerged, nMergedLen );
CPLFree( pszMerged );
aoRelationCollection.push_back( osRelation );
}
示例6: ACTextUnescape
CPLString ACTextUnescape( const char *pszRawInput, const char *pszEncoding )
{
CPLString osResult;
CPLString osInput = pszRawInput;
/* -------------------------------------------------------------------- */
/* Translate text from Win-1252 to UTF8. We approximate this */
/* by treating Win-1252 as Latin-1. Note that we likely ought */
/* to be consulting the $DWGCODEPAGE header variable which */
/* defaults to ANSI_1252 if not set. */
/* -------------------------------------------------------------------- */
osInput.Recode( pszEncoding, CPL_ENC_UTF8 );
const char *pszInput = osInput.c_str();
/* -------------------------------------------------------------------- */
/* Now translate escape sequences. They are all plain ascii */
/* characters and won't have been affected by the UTF8 */
/* recoding. */
/* -------------------------------------------------------------------- */
while( *pszInput != '\0' )
{
if( pszInput[0] == '\\' && pszInput[1] == 'P' )
{
osResult += '\n';
pszInput++;
}
else if( pszInput[0] == '\\' && pszInput[1] == '~' )
{
osResult += ' ';
pszInput++;
}
else if( pszInput[0] == '\\' && pszInput[1] == 'U'
&& pszInput[2] == '+' )
{
CPLString osHex;
int iChar;
osHex.assign( pszInput+3, 4 );
sscanf( osHex.c_str(), "%x", &iChar );
wchar_t anWCharString[2];
anWCharString[0] = (wchar_t) iChar;
anWCharString[1] = 0;
char *pszUTF8Char = CPLRecodeFromWChar( anWCharString,
CPL_ENC_UCS2,
CPL_ENC_UTF8 );
osResult += pszUTF8Char;
CPLFree( pszUTF8Char );
pszInput += 6;
}
else if( pszInput[0] == '\\'
&& (pszInput[1] == 'W'
|| pszInput[1] == 'T'
|| pszInput[1] == 'A' ) )
{
// eg. \W1.073172x;\T1.099;Bonneuil de Verrines
// See data/dwg/EP/42002.dwg
// Not sure what \W and \T do, but we skip them.
// According to qcad rs_text.cpp, \A values are vertical
// alignment, 0=bottom, 1=mid, 2=top but we ignore for now.
while( *pszInput != ';' && *pszInput != '\0' )
pszInput++;
}
else if( pszInput[0] == '\\' && pszInput[1] == '\\' )
{
osResult += '\\';
pszInput++;
}
else if( EQUALN(pszInput,"%%c",3)
|| EQUALN(pszInput,"%%d",3)
|| EQUALN(pszInput,"%%p",3) )
{
wchar_t anWCharString[2];
anWCharString[1] = 0;
// These are especial symbol representations for autocad.
if( EQUALN(pszInput,"%%c",3) )
anWCharString[0] = 0x2300; // diameter (0x00F8 is a good approx)
else if( EQUALN(pszInput,"%%d",3) )
anWCharString[0] = 0x00B0; // degree
else if( EQUALN(pszInput,"%%p",3) )
anWCharString[0] = 0x00B1; // plus/minus
char *pszUTF8Char = CPLRecodeFromWChar( anWCharString,
CPL_ENC_UCS2,
CPL_ENC_UTF8 );
osResult += pszUTF8Char;
CPLFree( pszUTF8Char );
pszInput += 2;
}
else
//.........这里部分代码省略.........
示例7: ScanForGCPs
void BSBDataset::ScanForGCPs( bool isNos, const char *pszFilename )
{
/* -------------------------------------------------------------------- */
/* Collect GCPs as appropriate to source. */
/* -------------------------------------------------------------------- */
nGCPCount = 0;
if ( isNos )
{
ScanForGCPsNos(pszFilename);
} else {
ScanForGCPsBSB();
}
/* -------------------------------------------------------------------- */
/* Apply heuristics to re-wrap GCPs to maintain continguity */
/* over the international dateline. */
/* -------------------------------------------------------------------- */
if( nGCPCount > 1 )
GDALHeuristicDatelineWrapGCPs( nGCPCount, pasGCPList );
/* -------------------------------------------------------------------- */
/* Collect coordinate system related parameters from header. */
/* -------------------------------------------------------------------- */
int i;
const char *pszKNP=NULL, *pszKNQ=NULL;
for( i = 0; psInfo->papszHeader[i] != NULL; i++ )
{
if( EQUALN(psInfo->papszHeader[i],"KNP/",4) )
{
pszKNP = psInfo->papszHeader[i];
SetMetadataItem( "BSB_KNP", pszKNP + 4 );
}
if( EQUALN(psInfo->papszHeader[i],"KNQ/",4) )
{
pszKNQ = psInfo->papszHeader[i];
SetMetadataItem( "BSB_KNQ", pszKNQ + 4 );
}
}
/* -------------------------------------------------------------------- */
/* Can we derive a reasonable coordinate system definition for */
/* this file? For now we keep it simple, just handling */
/* mercator. In the future we should consider others. */
/* -------------------------------------------------------------------- */
CPLString osUnderlyingSRS;
if( pszKNP != NULL )
{
const char *pszPR = strstr(pszKNP,"PR=");
const char *pszGD = strstr(pszKNP,"GD=");
const char *pszValue, *pszEnd = NULL;
const char *pszGEOGCS = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AUTHORITY[\"EPSG\",\"4326\"]]";
CPLString osPP;
// Capture the PP string.
pszValue = strstr(pszKNP,"PP=");
if( pszValue )
pszEnd = strstr(pszValue,",");
if( pszValue && pszEnd )
osPP.assign(pszValue+3,pszEnd-pszValue-3);
// Look at the datum
if( pszGD == NULL )
{
/* no match. We'll default to EPSG:4326 */
}
else if( EQUALN(pszGD,"GD=European 1950", 16) )
{
pszGEOGCS = "GEOGCS[\"ED50\",DATUM[\"European_Datum_1950\",SPHEROID[\"International 1924\",6378388,297,AUTHORITY[\"EPSG\",\"7022\"]],TOWGS84[-87,-98,-121,0,0,0,0],AUTHORITY[\"EPSG\",\"6230\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4230\"]]";
}
// Look at the projection
if( pszPR == NULL )
{
/* no match */
}
else if( EQUALN(pszPR,"PR=MERCATOR", 11) )
{
// We somewhat arbitrarily select our first GCPX as our
// central meridian. This is mostly helpful to ensure
// that regions crossing the dateline will be contiguous
// in mercator.
osUnderlyingSRS.Printf( "PROJCS[\"Global Mercator\",%s,PROJECTION[\"Mercator_2SP\"],PARAMETER[\"standard_parallel_1\",0],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",%d],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1]]",
pszGEOGCS, (int) pasGCPList[0].dfGCPX );
}
else if( EQUALN(pszPR,"PR=TRANSVERSE MERCATOR", 22)
&& osPP.size() > 0 )
{
osUnderlyingSRS.Printf(
"PROJCS[\"unnamed\",%s,PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",%s],PARAMETER[\"scale_factor\",1],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0]]",
pszGEOGCS, osPP.c_str() );
}
else if( EQUALN(pszPR,"PR=UNIVERSAL TRANSVERSE MERCATOR", 32)
&& osPP.size() > 0 )
//.........这里部分代码省略.........
示例8: atoi
//.........这里部分代码省略.........
delete poDS;
return NULL;
}
poDS->CaptureMetadataItem( achHeader + 3*16 );
poDS->CaptureMetadataItem( achHeader + 4*16 );
poDS->CaptureMetadataItem( achHeader + 5*16 );
poDS->CaptureMetadataItem( achHeader + 6*16 );
memcpy( &dfValue, achHeader + 7*16 + 8, 8 );
CPL_LSBPTR64( &dfValue );
osFValue.Printf( "%.15g", dfValue );
poDS->SetMetadataItem( "MAJOR_F", osFValue );
memcpy( &dfValue, achHeader + 8*16 + 8, 8 );
CPL_LSBPTR64( &dfValue );
osFValue.Printf( "%.15g", dfValue );
poDS->SetMetadataItem( "MINOR_F", osFValue );
memcpy( &dfValue, achHeader + 9*16 + 8, 8 );
CPL_LSBPTR64( &dfValue );
osFValue.Printf( "%.15g", dfValue );
poDS->SetMetadataItem( "MAJOR_T", osFValue );
memcpy( &dfValue, achHeader + 10*16 + 8, 8 );
CPL_LSBPTR64( &dfValue );
osFValue.Printf( "%.15g", dfValue );
poDS->SetMetadataItem( "MINOR_T", osFValue );
/* ==================================================================== */
/* Loop over grids. */
/* ==================================================================== */
int iGrid;
vsi_l_offset nGridOffset = sizeof(achHeader);
for( iGrid = 0; iGrid < nSubFileCount; iGrid++ )
{
CPLString osSubName;
int i;
GUInt32 nGSCount;
VSIFSeekL( poDS->fpImage, nGridOffset, SEEK_SET );
if (VSIFReadL( achHeader, 11, 16, poDS->fpImage ) != 16)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Cannot read header for subfile %d", iGrid);
delete poDS;
return NULL;
}
for( i = 4; i <= 9; i++ )
CPL_LSBPTR64( achHeader + i*16 + 8 );
CPL_LSBPTR32( achHeader + 10*16 + 8 );
memcpy( &nGSCount, achHeader + 10*16 + 8, 4 );
osSubName.assign( achHeader + 8, 8 );
osSubName.Trim();
// If this is our target grid, open it as a dataset.
if( iTargetGrid == iGrid || (iTargetGrid == -1 && iGrid == 0) )
{
if( !poDS->OpenGrid( achHeader, nGridOffset ) )
{
delete poDS;
return NULL;
}
}
// If we are opening the file as a whole, list subdatasets.
if( iTargetGrid == -1 )
{
CPLString osKey, osValue;
osKey.Printf( "SUBDATASET_%d_NAME", iGrid );
osValue.Printf( "NTv2:%d:%s", iGrid, osFilename.c_str() );
poDS->SetMetadataItem( osKey, osValue, "SUBDATASETS" );
osKey.Printf( "SUBDATASET_%d_DESC", iGrid );
osValue.Printf( "%s", osSubName.c_str() );
poDS->SetMetadataItem( osKey, osValue, "SUBDATASETS" );
}
nGridOffset += (11+(vsi_l_offset)nGSCount) * 16;
}
/* -------------------------------------------------------------------- */
/* Initialize any PAM information. */
/* -------------------------------------------------------------------- */
poDS->SetDescription( poOpenInfo->pszFilename );
poDS->TryLoadXML();
/* -------------------------------------------------------------------- */
/* Check for overviews. */
/* -------------------------------------------------------------------- */
poDS->oOvManager.Initialize( poDS, poOpenInfo->pszFilename );
return( poDS );
}
示例9: if
void GMLASXPathMatcher::SetDocumentMapURIToPrefix(
const std::map<CPLString,CPLString>& oMapURIToPrefix )
{
m_aosReferenceXPaths.clear();
// Split each reference XPath into its components
for(size_t i = 0; i < m_aosReferenceXPathsUncompiled.size(); ++i )
{
const CPLString& osXPath( m_aosReferenceXPathsUncompiled[i] );
std::vector<XPathComponent> oVector;
size_t iPos = 0;
bool bDirectChild = false;
if( osXPath.size() >= 2 &&
osXPath[0] == '/' && osXPath[1] == '/' )
{
iPos += 2;
}
else if( osXPath.size() >= 1 && osXPath[0] == '/' )
{
iPos += 1;
bDirectChild = true;
}
while( iPos < osXPath.size() )
{
size_t iPosNextSlash = osXPath.find('/', iPos);
if( iPos == iPosNextSlash )
{
bDirectChild = false;
iPos ++;
continue;
}
CPLString osCurNode;
if( iPosNextSlash == std::string::npos )
osCurNode.assign(osXPath, iPos, std::string::npos);
else
osCurNode.assign(osXPath, iPos, iPosNextSlash - iPos);
// Translate the configuration prefix to the equivalent in
// this current schema
size_t iPosColumn = osCurNode.find(':');
if( iPosColumn != std::string::npos )
{
bool bIsAttr = ( osCurNode[0] == '@' );
CPLString osPrefix;
CPLString osLocalname;
osPrefix.assign(osCurNode,
bIsAttr ? 1 : 0,
iPosColumn - (bIsAttr ? 1 : 0));
osLocalname.assign(osCurNode, iPosColumn+1,
std::string::npos);
std::map<CPLString, CPLString>::const_iterator oIter =
m_oMapPrefixToURIReferenceXPaths.find(osPrefix);
if( oIter != m_oMapPrefixToURIReferenceXPaths.end() )
{
const CPLString& osURI( oIter->second );
oIter = oMapURIToPrefix.find( osURI );
if( oIter == oMapURIToPrefix.end() )
break;
osPrefix.assign(oIter->second);
}
osCurNode.clear();
if( bIsAttr )
osCurNode.append(1, '@');
osCurNode.append(osPrefix);
osCurNode.append(1, ':');
osCurNode.append(osLocalname);
}
XPathComponent comp;
comp.m_osValue = osCurNode;
comp.m_bDirectChild = bDirectChild;
oVector.push_back(comp);
if( iPosNextSlash == std::string::npos )
iPos = osXPath.size();
else
iPos = iPosNextSlash + 1;
bDirectChild = true;
}
if ( iPos < osXPath.size() )
oVector.clear();
m_aosReferenceXPaths.push_back(oVector);
}
}
示例10: LoadDB
void GDALPamProxyDB::LoadDB()
{
/* -------------------------------------------------------------------- */
/* Open the database relating original names to proxy .aux.xml */
/* file names. */
/* -------------------------------------------------------------------- */
CPLString osDBName =
CPLFormFilename( osProxyDBDir, "gdal_pam_proxy", "dat" );
VSILFILE *fpDB = VSIFOpenL( osDBName, "r" );
nUpdateCounter = 0;
if( fpDB == NULL )
return;
/* -------------------------------------------------------------------- */
/* Read header, verify and extract update counter. */
/* -------------------------------------------------------------------- */
const size_t nHeaderSize = 100;
GByte abyHeader[nHeaderSize] = { '\0' };
if( VSIFReadL( abyHeader, 1, nHeaderSize, fpDB ) != nHeaderSize
|| !STARTS_WITH(reinterpret_cast<char *>(abyHeader), "GDAL_PROXY") )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Problem reading %s header - short or corrupt?",
osDBName.c_str() );
CPL_IGNORE_RET_VAL(VSIFCloseL(fpDB));
return;
}
nUpdateCounter = atoi(reinterpret_cast<char *>(abyHeader) + 10);
/* -------------------------------------------------------------------- */
/* Read the file in one gulp. */
/* -------------------------------------------------------------------- */
if( VSIFSeekL( fpDB, 0, SEEK_END ) != 0 )
{
CPL_IGNORE_RET_VAL(VSIFCloseL(fpDB));
return;
}
const int nBufLength = static_cast<int>(VSIFTellL(fpDB) - nHeaderSize);
if( VSIFSeekL( fpDB, nHeaderSize, SEEK_SET ) != 0 )
{
CPL_IGNORE_RET_VAL(VSIFCloseL(fpDB));
return;
}
char *pszDBData = static_cast<char *>( CPLCalloc(1,nBufLength+1) );
if( VSIFReadL( pszDBData, 1, nBufLength, fpDB ) !=
static_cast<size_t>(nBufLength) )
{
CPLFree(pszDBData);
CPL_IGNORE_RET_VAL(VSIFCloseL(fpDB));
return;
}
CPL_IGNORE_RET_VAL(VSIFCloseL( fpDB ));
/* -------------------------------------------------------------------- */
/* Parse the list of in/out names. */
/* -------------------------------------------------------------------- */
int iNext = 0;
while( iNext < nBufLength )
{
CPLString osOriginal;
osOriginal.assign( pszDBData + iNext );
for( ; iNext < nBufLength && pszDBData[iNext] != '\0'; iNext++ ) {}
if( iNext == nBufLength )
break;
iNext++;
CPLString osProxy = osProxyDBDir;
osProxy += "/";
osProxy += pszDBData + iNext;
for( ; iNext < nBufLength && pszDBData[iNext] != '\0'; iNext++ ) {}
iNext++;
aosOriginalFiles.push_back( osOriginal );
aosProxyFiles.push_back( osProxy );
}
CPLFree( pszDBData );
}
示例11: CSLTokenizeString
CPLString
OGRDXFWriterLayer::PrepareLineTypeDefinition( CPL_UNUSED OGRFeature *poFeature,
OGRStyleTool *poTool )
{
CPLString osDef;
OGRStylePen *poPen = (OGRStylePen *) poTool;
GBool bDefault;
const char *pszPattern;
/* -------------------------------------------------------------------- */
/* Fetch pattern. */
/* -------------------------------------------------------------------- */
pszPattern = poPen->Pattern( bDefault );
if( bDefault || strlen(pszPattern) == 0 )
return "";
/* -------------------------------------------------------------------- */
/* Split into pen up / pen down bits. */
/* -------------------------------------------------------------------- */
char **papszTokens = CSLTokenizeString(pszPattern);
int i;
double dfTotalLength = 0;
for( i = 0; papszTokens != NULL && papszTokens[i] != NULL; i++ )
{
const char *pszToken = papszTokens[i];
const char *pszUnit;
CPLString osAmount;
CPLString osDXFEntry;
// Split amount and unit.
for( pszUnit = pszToken;
strchr( "0123456789.", *pszUnit) != NULL;
pszUnit++ ) {}
osAmount.assign(pszToken,(int) (pszUnit-pszToken));
// If the unit is other than 'g' we really should be trying to
// do some type of transformation - but what to do? Pretty hard.
//
// Even entries are "pen down" represented as negative in DXF.
if( i%2 == 0 )
osDXFEntry.Printf( " 49\n-%s\n 74\n0\n", osAmount.c_str() );
else
osDXFEntry.Printf( " 49\n%s\n 74\n0\n", osAmount.c_str() );
osDef += osDXFEntry;
dfTotalLength += CPLAtof(osAmount);
}
/* -------------------------------------------------------------------- */
/* Prefix 73 and 40 items to the definition. */
/* -------------------------------------------------------------------- */
CPLString osPrefix;
osPrefix.Printf( " 73\n%d\n 40\n%.6g\n",
CSLCount(papszTokens),
dfTotalLength );
osDef = osPrefix + osDef;
CSLDestroy( papszTokens );
return osDef;
}