Example #1
0
CL_StringRef CL_XPathObject::get_string() const
{
	if (impl->type == type_string)
		return impl->string;
	else
		return CL_StringRef();
}
Example #2
0
CL_StringRef CL_CSSSelector::get_state(const CL_StringRef &path_element)
{
	CL_StringRef::size_type pos1 = path_element.find_first_of(':');
	if (pos1 == CL_StringRef::npos)
		return CL_StringRef();
	CL_StringRef::size_type pos2 = path_element.find_first_of(".#", pos1);
	if (pos2 == CL_StringRef::npos)
		return path_element.substr(pos1);
	else
		return path_element.substr(pos1, pos2 - pos1);
}
Example #3
0
inline CL_StringRef CL_XMLTokenizer_Generic::trim_whitespace(const CL_StringRef &text)
{
	CL_StringRef::size_type pos_start = text.find_first_not_of(" \t\r\n");
	if (pos_start == CL_StringRef::npos)
		return CL_StringRef();
	CL_StringRef::size_type pos_end = text.find_last_not_of(" \t\r\n", pos_start);
	if (pos_end == CL_StringRef::npos)
	{
		if (pos_start == 0)
			return text;
		else
			return string_allocator.alloc(text.substr(pos_start));
	}
	else
	{
		return string_allocator.alloc(text.substr(pos_start, pos_end - pos_start + 1));
	}
}
Example #4
0
CL_String CL_System::get_exe_path()
{
	char exe_file[PATH_MAX];
#ifdef __APPLE__
	CFBundleRef mainBundle = CFBundleGetMainBundle();
	if (mainBundle) 
	{
		CFURLRef mainURL = CFBundleCopyBundleURL(mainBundle);
		
		if (mainURL) 
		{
			int ok = CFURLGetFileSystemRepresentation (
				mainURL, (Boolean) true, (UInt8*)exe_file, PATH_MAX 
			);
			
			if (ok)
			{
				return CL_StringRef(exe_file) + "/";
			}
		}
	}
	
	throw CL_Exception("get_exe_path failed");

#else
#ifndef PROC_EXE_PATH
#define PROC_EXE_PATH "/proc/self/exe"
#endif
	int size;
	struct stat sb;
	if (lstat(PROC_EXE_PATH, &sb) < 0)
	{
#ifdef EXTERN___PROGNAME
		extern const char *__progname;
		char *pathenv, *name, *end;
		char fname[PATH_MAX];
		char cwd[PATH_MAX];
		struct stat sba;

		exe_file[0] = '\0';
		if ((pathenv = getenv("PATH")) != NULL)
		{
			for (name = pathenv; name; name = end)
			{
				if ((end = strchr(name, ':')))
					*end++ = '\0';
				snprintf(fname, sizeof(fname),
					"%s/%s", name, (char *)__progname);
				if (stat(fname, &sba) == 0) {
					snprintf(exe_file, sizeof(exe_file),
						"%s/", name);
					break;
				}
			}
		}
		// if getenv failed or path still not found
		// try current directory as last resort
		if (!exe_file[0])
		{
			if (getcwd(cwd, sizeof(cwd)) != NULL)
			{
				snprintf(fname, sizeof(fname),
					"%s/%s", cwd, (char *)__progname);
				if (stat(fname, &sba) == 0)
					snprintf(exe_file, sizeof(exe_file),
						"%s/", cwd);
			}
		}
		if (!exe_file[0])
			throw CL_Exception("get_exe_path: could not find path");
		else
			return CL_StringRef(exe_file);
#else
		throw CL_Exception("get_exe_path: proc file system not accesible");
#endif
	}
	else
	{
		size = readlink(PROC_EXE_PATH, exe_file, PATH_MAX);
		if (size < 0)
		{
			throw CL_Exception(strerror(errno));
		}
		else
		{
			exe_file[size] = '\0';
			return CL_StringRef(dirname(exe_file)) + "/";
		}
	}
#endif
	
}