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


C++ cString类代码示例

本文整理汇总了C++中cString的典型用法代码示例。如果您正苦于以下问题:C++ cString类的具体用法?C++ cString怎么用?C++ cString使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: CalculateHash

// ****************************************************************************
unsigned long cHashedString::CalculateHash(const cString & strIdent)
{
	if(strIdent.IsEmpty())
	{
		return 0;
	}
	// largest prime smaller than 65536
	unsigned long lBASE = 65521L;
	
	// lMAX is the largest n such that // 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
	unsigned int lMAX = 5522;

	unsigned int s1 = 0;
	unsigned int s2 = 0;

	int i = 0;
	unsigned int length = strIdent.GetLength();
	while(length > 0)
	{
		int k = length < lMAX ? length : lMAX;
		length -= k;
		while(--k >= 0)
		{
			s1 += (unsigned int)(tolower(strIdent[i++]) & 0XFF);
			s2 += s1;
		}
		s1 %= lBASE;
		s2 %= lBASE;
	}
	return ((s2 << 16) | s1);
}
开发者ID:AnkurSheel,项目名称:Engine,代码行数:32,代码来源:HashedString.cpp

示例2: SetTimeZone

bool cTimeAndDate::SetTimeZone(cString tz, bool isUTC, bool tostdout, cString external_exec) {
	cTimeAndDate *now;
	cExec exec;
	if(geteuid()==0) {
		now=new cTimeAndDate;
		now->SetUTC(isUTC);
		now->SetTimezone(tz);
		ofstream fout;
		if(tostdout) {
			if(!now->ApplyTimeZone(cout)) return false;
		} else {
			if(!cExec::CopyFile("/usr/share/zoneinfo/"+tz,"/etc/localtime")) {
				return false;
			}
			fout.open("/etc/sysconfig/clock");
			if(!now->ApplyTimeZone(fout)) {
				return false;
			}
			fout.close();
		}
		delete now;
	} else if(external_exec!="") {
		if(!external_exec.Contains(tz)) external_exec+=" -timezone "+tz;
		if(isUTC || external_exec.Contains("isUTC")) external_exec+=" -isUTC";
		if(!exec.ForkExecFG(external_exec)) {
			cerr<<"failed to exec: "<<external_exec<<endl;
			return false;
		}
	} else {
		cerr<<"not root, but no external_exec defined either"<<endl;
		return false;
	}
	return true;
}
开发者ID:cmd184psu,项目名称:fs-tools,代码行数:34,代码来源:timeanddate.cpp

示例3: FromFile

// ********** File IO **************** //
bool cStringList::FromFile(const cString & fname) {
	if(fname.Contains('*')) return false;
	#ifndef WIN32
	if(!FileExists(fname)) return false;
	struct stat buf;
	stat(fname,&buf);
	ifstream infile(fname);
	
	if(fname.Contains("/proc") || buf.st_size==0) {
		if(!FromFile(infile)) { infile.close(); return false; }
	} else {
		if(!FromFile(infile,buf.st_size)) { infile.close(); return false; }
	}
	infile.close();
	
	
	if((*this)[-1]=="" && Length()!=0) used--;
	#else
	FILE* fptr=fopen(fname,"r");
	FromFile(fptr);
	fclose(fptr);
	#endif
	
	return true;
}
开发者ID:cmd184psu,项目名称:fs-tools,代码行数:26,代码来源:stringlist.cpp

示例4: DoesDirectoryExist

// Verifies that directory exists.
// Returns success if the directory exists and is readable (failure may mean
// it's busy or permissions denied on win32)
//-----------------------------------------------------------------------------
CPUTResult CPUTFileSystem::DoesDirectoryExist(const cString &path)
{
#ifdef CPUT_OS_ANDROID
    // On Android, all files are in the APK and are compressed.
    // We do not have access to the standard file system, so
    // all files need streaming from memory through the android asset manager
    AAssetManager* assetManager = CPUTWindowAndroid::GetAppState()->activity->assetManager;
    
    AAssetDir* AssetDir = AAssetManager_openDir(assetManager, path.c_str());
    if (AssetDir)
        return CPUT_SUCCESS;
#else
    struct stat fileAttributes;
    
    int result = stat(path.c_str(), &fileAttributes);
    if (result == -1) {
        DEBUG_ERROR(strerror(errno));
        result = CPUT_ERROR; 
    }
	
    if (S_ISDIR(fileAttributes.st_mode)) {
        return CPUT_SUCCESS;
    }
#endif
    return CPUT_ERROR;
}
开发者ID:Cristianohh,项目名称:InstancingAndroid,代码行数:30,代码来源:CPUTOSServicesLinux.cpp

示例5: AssignStr

static void AssignStr(cString &dest, const char *start, const char *end, _locale_t locale)
{
	dest.clear();
	if (end <= start)
    {
		return;
    }

	static const int NBUF = 64;
	wchar_t buf[NBUF];
	int nb = 0;

	size_t len = end - start;
	size_t initial = len + 1; // assume most characters are 1-byte
	dest.reserve(initial);

	const char *p = start;
	while (p < end)
	{
		int len = _mbtowc_l(&buf[nb++], p, end - p, locale);
		if (len < 1)
        {
			break;
        }

		p += len;
		if (p >= end || nb >= NBUF)
		{
			dest.append(buf, nb);
			nb = 0;
		}
	}
}
开发者ID:Clever-Boy,项目名称:CloudsGPUPro6,代码行数:33,代码来源:CPUTConfigBlock.cpp

示例6: iCPUTifstream

CPUTFileSystem::CPUTandroidifstream::CPUTandroidifstream(const cString &fileName, std::ios_base::openmode mode) : iCPUTifstream(fileName, mode)
{
    mpAsset = NULL;
    mpAssetDir = NULL;
    mbEOF = true;
    
    // Extract the file and dir
    int length = fileName.length();
    int index = fileName.find_last_of("\\/");
    cString file = fileName.substr(index + 1, (length - 1 - index));
    cString dir  = fileName.substr(0, index);
    
    // On Android, all files are in the APK and are compressed.
    // We do not have access to the standard file system, so
    // all files need streaming from memory through the android asset manager
    AAssetManager* assetManager = CPUTWindowAndroid::GetAppState()->activity->assetManager;
    
    mpAssetDir = AAssetManager_openDir(assetManager, dir.c_str());
    if (!mpAssetDir)
        DEBUG_PRINT("Failed to load asset Dir");
    
    const char* assetFileName = NULL;
    while ((assetFileName = AAssetDir_getNextFileName(mpAssetDir)) != NULL) 
    {
        if (strcmp(file.c_str(), assetFileName) == 0)
        {
            // For some reason we need to pass in the fully pathed filename here, rather than the relative filename
            // that we have just been given. This feels like a bug in Android!
            mpAsset = AAssetManager_open(assetManager, fileName.c_str()/*assetFileName*/, AASSET_MODE_STREAMING);
            if (mpAsset)
                mbEOF = false;
            return;
        }
    }
}
开发者ID:Cristianohh,项目名称:InstancingAndroid,代码行数:35,代码来源:CPUTOSServicesLinux.cpp

示例7: FileList_R

void FileList_R(cStringList &mylist, cString fullpath, bool usedirs) {
	cStringList split;
//	cerr<<"fullpath="<<fullpath<<endl;
	if(fullpath.Contains('*')) 
		split.FromString(fullpath,"*.");
	else
		split.FromString(fullpath,".");
	FileList_R(mylist,fullpath.ChopRt('/'),fullpath.ChopAllLf('/'),usedirs);
}
开发者ID:cmd184psu,项目名称:fs-tools,代码行数:9,代码来源:changeend.cpp

示例8: FileList_1

void FileList_1(cStringList &mylist, cString fullpath, bool usedirs) {
	cStringList split;
	if(fullpath.Contains('*')) 
		split.FromString(fullpath,"*.");
	else
		split.FromString(fullpath,".");
		
	FileList_1(mylist,fullpath.ChopRt('/'),fullpath.ChopAllLf('/'),usedirs);
}
开发者ID:cmd184psu,项目名称:fs-tools,代码行数:9,代码来源:changeend.cpp

示例9: pad

cString cString::pad(const cString& object,
                     uint number,
                     character padding)
{
    if (object.length() >= number)
        return object;

    return object + dup(" ", number - object.length());
}
开发者ID:eladraz,项目名称:xStl,代码行数:9,代码来源:string.cpp

示例10: MapKey

CPUTKey MapKey(cString strKey)
{
    for(int i = 0; i < KEY_NUM_KEYS; i++)
    {
        if( 0 == strKey.compare(CPUTKeyMap[i].name))
            return CPUTKeyMap[i].value;
    }
    DEBUG_PRINT(_L("Unknown Key: %s"), strKey.c_str());
    return KEY_NUM_KEYS;
}
开发者ID:swq0553,项目名称:ClusteredShadingAndroid,代码行数:10,代码来源:CPUTGUIElement.cpp

示例11:

//Converts a string day into it's number
int cTimeAndDate::Day2Number(cString day,int st) {
	day=day.ToUpper();
	if(day.Contains("SUN")) return ((0-st)+7)%7;
	if(day.Contains("MON")) return ((1-st)+7)%7;
	if(day.Contains("TUE")) return ((2-st)+7)%7;
	if(day.Contains("WED")) return ((3-st)+7)%7;
	if(day.Contains("THU")) return ((4-st)+7)%7;
	if(day.Contains("FRI")) return ((5-st)+7)%7;
	if(day.Contains("SAT")) return ((6-st)+7)%7;
	return -1;
}
开发者ID:cmd184psu,项目名称:fs-tools,代码行数:12,代码来源:timeanddate.cpp

示例12: CleanConfigurationOptions

//
// This function parses configuration options from a text string. Removes any previous
// options stored in the configuration list.
//
void CommandParser::ParseConfigurationOptions(cString arguments, cString delimiter)
{
	CleanConfigurationOptions();

	std::vector<cString> argumentList;

	size_t pos;
	size_t nextPos = arguments.find_first_of(delimiter, 0);

	//
	// Break out parameters from command line
	//
	while (nextPos != std::string::npos) {
		pos = nextPos + 1;
		nextPos = arguments.find_first_of(delimiter, pos);
		argumentList.push_back(arguments.substr(pos, nextPos - pos));
	}

	//
	// Remove leading spaces from arguments.
	//
	for (std::vector<cString>::iterator it = argumentList.begin(); it != argumentList.end(); it++) {
		std::string::size_type pos = it->find_first_not_of(' ');
		if (pos != std::string::npos) {
			it->erase(0, pos);
		}
	}

	//
	// Remove trailing spaces from arguments
	//
	for (std::vector<cString>::iterator it = argumentList.begin(); it != argumentList.end(); it++) {
		std::string::size_type pos = it->find_last_not_of(' ');
		if (pos != std::string::npos) {
			it->erase(pos + 1);
		}
	}

	//
	// Split the values from the parameter name
	//
	cString arg;
	for (std::vector<cString>::iterator it = argumentList.begin(); it != argumentList.end(); it++) {
		arg = *it;
		pos = arg.find_first_of(_L(":"), 0);
		if (pos != cString::npos) {
			m_ArgumentMap.insert(std::make_pair(arg.substr(0, pos), arg.substr(pos + 1, std::string::npos)));
		} else {
			m_ArgumentMap.insert(std::make_pair(arg.substr(0, pos), _L("")));
		}
	}

	return;
}
开发者ID:Cristianohh,项目名称:InstancingAndroid,代码行数:58,代码来源:CPUTParser.cpp

示例13: rfind

uint cString::rfind(const cString& string,
                    uint startIndex) const
{
    uint i  = startIndex;
    uint ln = length();
    uint on = string.length();

    // Incase of empty string. Always match
    if (on == 0)
    {
        return startIndex;
    }

    // If the current string is empty, search failed.
    if (ln == 0)
        return 0;

    // If this string doesn't have at least the number of characters 'string'
    // has, the search will probably failed. Returns the length of this string.
    if (ln < on)
        return ln;

    // Set the postion to the end of the string
    if (i >= ln - on)
        i = ln - on;

    bool shouldExit = false;
    do
    {
        /* Try to find a match */
        if (m_buffer->getBuffer()[i] == string.m_buffer->getBuffer()[0])
        {
            /* Scan the reset of the string */
            uint j;
            for (j = i + 1;
                 ((j < ln) && (j < i + on) && (string.m_buffer->getBuffer()[j - i] == m_buffer->getBuffer()[j]));
                 j++)
            {
                /* Match is ok */
            }
            if (j == i + string.length())
                return i;
        }
        // Since i is uint...
        if (i == 0)
            shouldExit = true;
        else
            i--;
    } while (!shouldExit);

    return ln;
}
开发者ID:eladraz,项目名称:xStl,代码行数:52,代码来源:string.cpp

示例14: Resize

/*int cStringList::FromMem(struct memfile &f) {
	int len;
	int bytes=0;
	bytes+=memread(f,&len,sizeof(int));
	cString temp="";
	char * tempchar=NULL;
	for(int i=0; i<len; i++) {
		tempchar=(char*)f.start;
		tempchar+=f.offset;
		temp=tempchar;
		
		bytes+=temp.Length()+1;
		f.offset+=temp.Length()+1;
		(*this)+=temp;
		temp="";
	}
	if((*this)[-1]=="" && Length()!=0) used--;
	return bytes;
}
*/
void cStringList::FromString(const cString &strng, cString delim) {
	if(delim.Length()==1) return FromString(strng,delim[0]);
	delete [] Array;
	Array=NULL;
	allocated=0;
	used=0;	
	Resize(500);
		
	cString substrng=delim;
	cString temp;
	used=1;
	for(int i=0; i<strng.Length(); ) FromString_innerloop(strng,delim,substrng, i);
}
开发者ID:cmd184psu,项目名称:fs-tools,代码行数:33,代码来源:stringlist.cpp

示例15: FromString_innerloop

void cStringList::FromString_innerloop(const cString & strng, cString delim, cString &substrng, int & i) {
	int s=strng.Length();
	for(int j=0; j<delim.Length() && i+j<strng.Length(); j++) substrng[j]=strng[i+j];
	if(substrng!=delim && i<s) {
		if(used+1>allocated) {
			Resize(allocated+500);
		}
		Array[used-1]+=strng[i];
		i++;
	} else {
		used++;
		i+=substrng.Length();
	}
}
开发者ID:cmd184psu,项目名称:fs-tools,代码行数:14,代码来源:stringlist.cpp


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