当前位置: 首页>>代码示例>>C++>>正文


C++ STRING::substr方法代码示例

本文整理汇总了C++中STRING::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ STRING::substr方法的具体用法?C++ STRING::substr怎么用?C++ STRING::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在STRING的用法示例。


在下文中一共展示了STRING::substr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SetPartName

int LPID::SetPartName( const STRING& aPartName )
{
    STRING  category;
    STRING  base;
    int     offset;
    int     separation = int( aPartName.find_first_of( "/" ) );

    if( separation != -1 )
    {
        category = aPartName.substr( 0, separation );
        base     = aPartName.substr( separation+1 );
    }
    else
    {
        // leave category empty
        base = aPartName;
    }

    if( (offset = SetCategory( category )) != -1 )
        return offset;

    if( (offset = SetBaseName( base )) != -1 )
    {
        return offset + separation + 1;
    }

    return -1;
}
开发者ID:AlexanderBrevig,项目名称:kicad-source-mirror,代码行数:28,代码来源:sch_lpid.cpp

示例2: Trim

bool JustRenderIt::ResourceManager::GetResourcePath(STRING& filename,
                                                    STRING folderName)
{
  Trim(filename);
  Trim(folderName);
  if(folderName[folderName.length()-1] == '/' ||
     folderName[folderName.length()-1] == '\\' )
    folderName = folderName.substr(0, folderName.length()-1);
  if(folderName[0] == '/')
    folderName = folderName.substr(1, folderName.length()-1);

  if(!FileExists(filename))
  {
    STRING newfilename = "../resources/";
    newfilename += folderName + "/" + filename;
    if(!FileExists(newfilename))
    {
      char str[256];
      sprintf(str, "Couldn't open \"%s\"", filename.c_str());
      LOG_ERROR1(str);
      return false;
    }
    filename = newfilename;
  }
  return true;
}
开发者ID:ranjiao,项目名称:JustRenderIt,代码行数:26,代码来源:Resource.cpp

示例3: GetParenthesisedList

// Break up a string composed of multiple sections in parentheses into a collection
// of sub-strings. Sample input string: (Hello)(World1,World2)
MgStringCollection* WfsGetFeatureParams::GetParenthesisedList(CREFSTRING sourceString)
{
    MgStringCollection* stringList = new MgStringCollection();
    if(sourceString.length() > 0)
    {
        // Create a collection of strings
        STRING remaining = MgUtil::Trim(sourceString);
        while(remaining.length() > 0)
        {
            STRING::size_type openParenthesis = remaining.find_first_of(L"(");
            if(openParenthesis != string::npos)
            {
                STRING::size_type closeParenthesis = remaining.find_first_of(L")");
                if(closeParenthesis != string::npos)
                {
                    STRING thisString = remaining.substr(openParenthesis + 1, closeParenthesis - openParenthesis - 1);
                    stringList->Add(thisString);
                    remaining = remaining.substr(closeParenthesis + 1);
                }
            }
            else
            {
                stringList->Add(remaining);
                break;
            }
        }
    }
    return stringList;
}
开发者ID:kanbang,项目名称:Colt,代码行数:31,代码来源:WfsGetFeatureParams.cpp

示例4:

CKT::CVersion::CVersion(STRING version)
{
	int iPoint = version.find('.');
	STRING sTemp = version.substr(0, iPoint);
	m_byMajor = (BYTE)toInt(sTemp.c_str());

	sTemp = version.substr(iPoint + 1, version.length() - iPoint);
	m_byMinor = (BYTE)toInt(sTemp.c_str());
}
开发者ID:Chefkoch85,项目名称:D3D_2D_Engine,代码行数:9,代码来源:Version.cpp

示例5: DeleteFilesFromDirectory

void OSInterface::DeleteFilesFromDirectory(const STRING& aRootDir,const STRING& aExtension)                    
	{
	STRING			patternOfString;
	WIN32_FIND_DATA fileInfo;
    patternOfString = aRootDir + _T("\\*.*") ;
	
	HANDLE hToFile = ::FindFirstFile(patternOfString.c_str(), &fileInfo);	
	
	if(hToFile != INVALID_HANDLE_VALUE)
		{
		do
			{
			if(fileInfo.cFileName[0] != '.')
				{
				
				STRING file = fileInfo.cFileName;
				
				STRING extOfString = file.substr(file.rfind(_T(".")) + 1);

				if(extOfString == aExtension)
					{
					::DeleteFile(file.c_str());
					}
				}		
			}while(::FindNextFile(hToFile , &fileInfo));

		::FindClose(hToFile);
	  	}
	}
开发者ID:cdaffara,项目名称:symbiandump-mw1,代码行数:29,代码来源:osinterface.cpp

示例6: GenerateDefinitions

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);
        }
    }

}
开发者ID:kanbang,项目名称:Colt,代码行数:44,代码来源:WmsLayerDefinitions.cpp

示例7: removePath

/*
 * Remove the path from a file name, perserving folders.
 * preserveFrom should carry a trailing \.
 */
STRING removePath(const STRING str, const STRING preserveFrom)
{
	const int pos = str.find(preserveFrom);
	if (pos != str.npos)
	{
		return str.substr(pos + preserveFrom.length());
	}
	// Return the path unaltered, since it didn't contain the
	// default folder and any other folders should be subfolders
	// (although a different default folder may be present).
	return str;
}
开发者ID:LameAss-Studio,项目名称:trans3,代码行数:16,代码来源:paths.cpp

示例8: trim

static void trim(STRING& str)
{
    static const WCHAR Spaces[] = L" \t\r\n";
    size_t i = str.find_first_not_of(Spaces);
    size_t j = str.find_last_not_of(Spaces);
    if (i == STRING::npos || j == STRING::npos)
    {
        str.clear();
    }
    else
    {
        str = str.substr(i, j - i + 1);
    }
}
开发者ID:Moteesh,项目名称:reactos,代码行数:14,代码来源:fontsub.cpp

示例9: IsInteger

const std::vector <STRING>  OSInterface::ExtractFilesFromDirectory(const STRING& aRootDir,const STRING& aExtension)                    
	{
	STRING			pathOfFile;
	STRING			patternOfString;
	WIN32_FIND_DATA fileInfo;

    patternOfString = aRootDir + _T("\\*.*") ;

	HANDLE hToFile = ::FindFirstFile(patternOfString.c_str(), &fileInfo);	
	
	std::vector<STRING> aDirFiles;

	if(hToFile != INVALID_HANDLE_VALUE)
		{
		do
			{
			if(fileInfo.cFileName[0] != '.')
				{
				pathOfFile.erase();
				
				pathOfFile = aRootDir + _T("\\")+ fileInfo.cFileName;
				STRING file = fileInfo.cFileName;
								
				STRING extOfString = file.substr(file.rfind(_T(".")) + 1);
				
				if(aExtension.length())
					{
					if(extOfString == aExtension)
						{
						aDirFiles.push_back(pathOfFile);
						}
					}
				else
					{
					bool valid = IsInteger(file);
					if(valid)
						{
						aDirFiles.push_back(pathOfFile);
						}
					}
				}
			}while(::FindNextFile(hToFile , &fileInfo));

		::FindClose(hToFile);
	  	}
	return aDirFiles;
	}
开发者ID:cdaffara,项目名称:symbiandump-mw1,代码行数:47,代码来源:osinterface.cpp

示例10: FileName

// Get file name from path
STRING Port::FileName(STRING file)
{
#ifdef WIN32
#ifdef UNICODE
	int pos = file.find_last_of(L"\\") + 1;
#else
	int pos = file.find_last_of("\\") + 1;
#endif
#elif defined(UNIX)
#ifdef UNICODE
	int pos = file.find_last_of(L"/") + 1;
#else
	int pos = file.find_last_of("/") + 1;
#endif
#endif
	return file.substr(pos);
}
开发者ID:McTwist,项目名称:PixelMap,代码行数:18,代码来源:Utility.cpp

示例11: draw_textFontM

/*! 
// \param char * str : 
// \param int offset : 
// \param SDL_Surface* screen : 
*/
void cCredits::draw_textFontM(char* pstrLine, int offset, SDL_Surface* screen)
{
	ASSERT(m_pMainFont);

    int tx, ty;
	TTF_SizeText(m_pMainFont,pstrLine, &tx, &ty);
	int iY = screen->h - (offset * ty);
	SDL_Rect trect;
	STRING strLayout = pstrLine;
	STRING strRes = strLayout;
	size_t iLen = strRes.length(); 
	if (pstrLine[0] == '-')
	{
		// highlight
		// eat '-'
		strRes = strLayout.substr(1,iLen - 1); 
		trect.y= iY - 2;
		//trect.x =  (screen->w/2 - ((int)strRes.size()*tx + 3)/2) - 4;
        trect.x =  (screen->w  - tx)/ 2;
		//trect.w = (int)strRes.size()*tx + 8;
        trect.w = tx;
		trect.h = ty + 4;
        SDL_Rect rctBox = trect;
        rctBox.x -= 4;
        rctBox.w += 4;
		Uint32 tcolor = SDL_MapRGBA(screen->format, 128, 0, 0,255);
		SDL_FillRect(screen,&rctBox,tcolor);
	}
	else
	{
		trect.y= iY - 2;
		trect.x =  (screen->w  - tx)/ 2;
		
	}
    GFX_UTIL::DrawString(screen, strRes.c_str(), trect.x, 
                                trect.y, m_colCurrent, m_pMainFont,false);

}
开发者ID:aaaasmile,项目名称:tressettecpp,代码行数:43,代码来源:credits.cpp

示例12: trim

/*
 * Trim whitespace from the sides of a string.
 *
 * str (in) - string to trim
 * return (out) - trimmed string
 */
STRING parser::trim(const STRING &str)
{
	const int len = str.length();
	if (len == 0) return _T("");
	int start = -1, end = -1;
	for (int i = 0; i < len; i++)
	{
		if (str[i] != _T(' ') && str[i] != _T('\t'))
		{
			start = i;
			break;
		}
	}
	if (start == -1) return _T("");
	for (int j = len - 1; j >= 0; j--)
	{
		if (str[j] != _T(' ') && str[j] != _T('\t'))
		{
			end = j + 1 - start;
			break;
		}
	}
	return str.substr(start, end);
}
开发者ID:shao113,项目名称:trans3,代码行数:30,代码来源:parser.cpp

示例13: GetMetadataDefinitions

bool MgWmsLayerDefinitions::GetMetadataDefinitions(MgUtilDictionary& Dictionary)
{
//    STRING sDebug = m_xmlParser->Current().Contents();
    // We're looking for a <ResourceDocumentHeader ...>
    MgXmlSynchronizeOnElement ElementResourceDocumentHeader(*m_xmlParser,_("ResourceDocumentHeader"));
    if(!ElementResourceDocumentHeader.AtBegin())
        return false;

    // And inside that, there's a <Metadata ...>
    MgXmlSynchronizeOnElement ElementMetadata(*m_xmlParser,_("Metadata"));
    if(!ElementMetadata.AtBegin())
        return false;

    // And inside *that*, we hope there's a <Simple...>
    MgXmlSynchronizeOnElement ElementSimple(*m_xmlParser,_("Simple"));
    if(!ElementSimple.AtBegin())
        return false;

    // And once we're here, we hope to find a grunch of <Property...> elements
    while(!ElementSimple.AtEnd()) {
        MgXmlSynchronizeOnElement ElementProperty(*m_xmlParser,_("Property"));
        if(ElementProperty.AtBegin()) {
            // Each of which consist of <Name> and <Value> pairs...
            STRING sName;
            STRING sValue;
            if(GetElementContents(_("Name"),sName) && GetElementContents(_("Value"),sValue)) {
                STRING sDefinitionName =  _("Layer.");
                // Present the names slightly differently than internal representation.
                // System-defined metadata is published with an underscore prefix.  We
                // publish this without the underscore: "_Bounds" -> "Layer.Bounds".
                // User-defined metadata will not have the underscore, and we present
                // this for consumption as "Layer.user.Whatever" -- just to make sure
                // that the user and system namespaces remain distinct.
                if(sName[0] == '_')
                    sDefinitionName += sName.substr(1);
                else
                    sDefinitionName += _("user.") + sName;

                //----------------------------------------------------------------------
                // If it starts and ends with escaped angled brackets, let's assume it's
                // "corrupted" XML that simply needs unescaping.
                //
                // TODO: This is not meant to be a long-term solution; it just overcomes
                // a current schema restriction on metadata consisting of mixed content.
                STRING::size_type iLt =sValue.find(_("&lt;"));
                STRING::size_type iGt = sValue.rfind(_("&gt;"));
                STRING::size_type iLen = sValue.length();
                if(sValue.find(_("&lt;")) == 0 && sValue.rfind(_("&gt;")) == sValue.length() - 4) {
                  STRING::size_type iPos;
                  while((iPos = sValue.find(_("&lt;")))  != STRING::npos)
                    sValue = sValue.substr(0,iPos) + _("<") + sValue.substr(iPos+4);
                  while((iPos = sValue.find(_("&gt;")))  != STRING::npos)
                    sValue = sValue.substr(0,iPos) + _(">") + sValue.substr(iPos+4);
                  while((iPos = sValue.find(_("\x201d")))  != STRING::npos)
                    sValue = sValue.substr(0,iPos) + _("\"") + sValue.substr(iPos+1);
                }
                //----------------------------------------------------------------------

                Dictionary.AddDefinition(sDefinitionName,sValue);
            }
        }
    }

    return true;
}
开发者ID:kanbang,项目名称:Colt,代码行数:65,代码来源:WmsLayerDefinitions.cpp

示例14: Execute

/// <summary>
/// Executes the specific request.
/// </summary>
/// <returns>
/// MgHttpResponse
/// This contains the response (including MgHttpResult and StatusCode) from the server.
/// </returns>
void MgHttpWfsDescribeFeatureType::Execute(MgHttpResponse& hResponse)
{
    Ptr<MgHttpResult> hResult = hResponse.GetResult();

    MG_HTTP_HANDLER_TRY()

    // We have to wrap the request parameters, since the outside
    // world is case-sensitive (with respect to names,) but
    // we need our parameters NOT to be so.
    Ptr<MgHttpRequestParam> origReqParams = m_hRequest->GetRequestParam();
    MgHttpRequestParameters Parms(origReqParams);
    MgHttpResponseStream Out;

    MgOgcServer::SetLoader(GetDocument);

    MgUserInformation::SetCurrentUserInfo(m_userInfo);

    // Instance a server-lette
    MgOgcWfsServer Wfs(Parms,Out);

    // Determine required feature types
    CPSZ pszFeatureTypes = Wfs.RequestParameter(MgHttpResourceStrings::reqWfsTypeName.c_str());
    STRING sFeatureTypes = pszFeatureTypes? pszFeatureTypes : _("");
    Ptr<MgStringCollection> featureTypeList;
    if(sFeatureTypes.empty())
    {
        featureTypeList = NULL;
    }
    else
    {
        featureTypeList = MgStringCollection::ParseCollection(sFeatureTypes, L",");
    }

    Ptr<MgResourceService> pResourceService = (MgResourceService*)(CreateService(MgServiceType::ResourceService));
    Ptr<MgFeatureService> pFeatureService = (MgFeatureService*)(CreateService(MgServiceType::FeatureService));

    // Retrieve feature definitions
    auto_ptr<MgWfsFeatureDefinitions> pFeatureTypes;
    if(NULL == featureTypeList)
    {
        pFeatureTypes.reset(new MgWfsFeatureDefinitions(pResourceService,pFeatureService));
    }
    else
    {
        pFeatureTypes.reset(new MgWfsFeatureDefinitions(pResourceService,pFeatureService,featureTypeList));
    }
    Wfs.SetFeatureDefinitions(pFeatureTypes.get());

    // In order to validate request we have to invoke the ProcessRequest
    if(!Wfs.ProcessRequest(this))
    {
        // Obtain the response byte reader
        Ptr<MgByteReader> errorResponse = Out.Stream().GetReader();

        // Set the result
        hResult->SetResultObject(errorResponse, errorResponse->GetMimeType());
        return;
    }

    // Determine required output format
    // This part must behind the Wfs.ProcessRequest, where parameters have been validated.
    CPSZ pszOutputFormat = Wfs.RequestParameter(MgHttpResourceStrings::reqWfsOutputFormat.c_str());
    STRING sOutputFormat = pszOutputFormat? pszOutputFormat : _("");
    if(sOutputFormat.empty())
    {
        sOutputFormat = Wfs.GetDefaultDescribeFeatureTypeOutputFormat(STRING(Wfs.RequestParameter(MgHttpResourceStrings::reqWfsVersion.c_str())));
    }

    if(pFeatureTypes->InSameNamespace()) 
    {
        STRING sPrefix = L"";
        STRING sUrl = L"";
        STRING sResource = L""; // TODO: look for this in arg, since POST may put it there to save us trouble.
        STRING sSchemaHash = L"";
        Ptr<MgResourceIdentifier> idResource;
        Ptr<MgStringCollection> pFeatureClasses = new MgStringCollection();

        while(pFeatureTypes->ReadNext())
        {
            STRING sClassFullName = pFeatureTypes->GetClassFullName();
            
            if(!sFeatureTypes.empty() && STRING::npos == sFeatureTypes.find(sClassFullName))
            {
                continue;
            }

            STRING::size_type iPos = sClassFullName.find(_(":")); //NOXLATE
            if(iPos != STRING::npos)
            {
                if(sPrefix.empty())
                {
                    sPrefix = sClassFullName.substr(0,iPos);
                }
//.........这里部分代码省略.........
开发者ID:kanbang,项目名称:Colt,代码行数:101,代码来源:HttpWfsDescribeFeatureType.cpp

示例15: Format

STRING LPID::Format( const STRING& aLogicalLib, const STRING& aPartName, const STRING& aRevision )
    throw( PARSE_ERROR )
{
    STRING  ret;
    int     offset;

    if( aLogicalLib.size() )
    {
        offset = okLogical( aLogicalLib );
        if( offset != -1 )
        {
            THROW_PARSE_ERROR(
                    _( "Illegal character found in logical lib name" ),
                    wxString::FromUTF8( aLogicalLib.c_str() ),
                    aLogicalLib.c_str(),
                    0,
                    offset
                    );
        }
        ret += aLogicalLib;
        ret += ':';
    }

    {
        STRING  category;
        STRING  base;

        int separation = int( aPartName.find_first_of( "/" ) );

        if( separation != -1 )
        {
            category = aPartName.substr( 0, separation );
            base     = aPartName.substr( separation+1 );
        }
        else
        {
            // leave category empty
            base = aPartName;
        }

        if( (offset = okCategory( category )) != -1 )
        {
            THROW_PARSE_ERROR(
                    _( "Illegal character found in category" ),
                    wxString::FromUTF8( aRevision.c_str() ),
                    aRevision.c_str(),
                    0,
                    offset
                    );
        }

        if( (offset = okBase( base )) != -1 )
        {
            THROW_PARSE_ERROR(
                    _( "Illegal character found in base name" ),
                    wxString::FromUTF8( aRevision.c_str() ),
                    aRevision.c_str(),
                    0,
                    offset + separation + 1
                    );
        }

        if( category.size() )
        {
            ret += category;
            ret += '/';
        }

        ret += base;
    }

    if( aRevision.size() )
    {
        offset = okRevision( aRevision );
        if( offset != -1 )
        {
            THROW_PARSE_ERROR(
                    _( "Illegal character found in revision" ),
                    wxString::FromUTF8( aRevision.c_str() ),
                    aRevision.c_str(),
                    0,
                    offset
                    );
        }

        ret += '/';
        ret += aRevision;
    }

    return ret;
}
开发者ID:AlexanderBrevig,项目名称:kicad-source-mirror,代码行数:91,代码来源:sch_lpid.cpp


注:本文中的STRING::substr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。