Ejemplo n.º 1
0
bool getTok(const gkString& buf, const gkString& dim, gkString& tok, size_t &start)
{
	const size_t size = buf.size();
	const size_t dimsize = dim.size();

	size_t pos = gkString::npos;

	while (start < size) 
	{
		pos = buf.find(dim, start);
		
		if (pos == gkString::npos) 
			pos = size;
		
		if (start == pos)
			start += dimsize; 
		else
			break;
	}

	if (start >= size) return false;

	tok.assign(&buf[start], pos-start);
	start = pos + dimsize;

	return true;
}
Ejemplo n.º 2
0
BOM getTextBom(gkString& line, bool removeBom) 
{
	size_t len = line.size();
	BOM bom = getTextEncoding(line.c_str(), len);
	if (bom != BOM_NONE && removeBom) {
		//strip bom
		line = line.substr(getBOMLength(bom));
	}
	return bom;
}
Ejemplo n.º 3
0
void splitFileName(const gkString& path, gkString& dir, gkString& base, gkString& ext)
{
	if (path.empty()) return;
	if (path == "." || path == "..")
	{
		dir = path;
		return;
	}

	gkString fpath = path, fname;

	char delim = '/';

	bool bdelim = fpath.find_last_of('\\') != gkString::npos;
	bool fdelim = fpath.find_last_of('/')  != gkString::npos;

	if (bdelim) 
	{
		if (fdelim) //normalize to \ to /
			std::replace(fpath.begin(), fpath.end(), '\\', '/');
		else
			delim = '\\';
	} 

	size_t i = fpath.find_last_of(delim);

	if (i != gkString::npos) 
	{
		dir = fpath.substr(0, i);
		fname = fpath.substr(i+1, path.size()-1);
	} 
	else 
	{
		dir.clear();
		fname = fpath;
	}

	i = fname.find_last_of('.');
	if (i != gkString::npos) 
	{
		base = fname.substr(0, i);
		ext = fname.substr(i+1, fname.size()-1);
	} 
	else 
	{
		base = fname;
		ext.clear();
	}
}