Esempio n. 1
0
void MakeLowerCaseInplace(string & s)
{
  UniString uniStr;
  utf8::unchecked::utf8to32(s.begin(), s.end(), back_inserter(uniStr));
  MakeLowerCaseInplace(uniStr);
  s.clear();
  utf8::unchecked::utf32to8(uniStr.begin(), uniStr.end(), back_inserter(s));
}
bool FSGetApplPath(UniString &applPath, bool withPS/* = true*/)
{
#if defined(WIN32) || defined(_WIN32_WCE)

    wchar_t    Temp[_MAX_PATH+1] = L"";
#if defined(_WIN32_WCE)
	::GetModuleFileName(NULL, Temp, _MAX_PATH);
#else
	::GetModuleFileNameW(NULL, Temp, _MAX_PATH);
#endif

	applPath = Temp;

	STRIndex_t pos = applPath.FindRAt(PATH_SEPARATOR_CHAR);
	if ( STRING_FOUND(pos) )
		applPath.Truncate( withPS ? pos + 1 : pos);

	return true;

#else

	CFBundleRef	bundleRef = CFBundleGetMainBundle();
	if ( bundleRef == NULL ) return false;

	CFURLRef	urlRef = CFBundleCopyBundleURL(bundleRef);
	CFRelease(bundleRef);

	if ( urlRef )
	{
		CFStringRef	stringRef = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle);
		CFRelease(urlRef);

		if ( stringRef )
		{
			applPath = stringRef;
			CFRelease(stringRef);
	
			STRIndex_t pos = applPath.FindRAt(PATH_SEPARATOR_CHAR);
			if ( STRING_FOUND(pos) )
			{
				if (!withPS)
					applPath.Truncate(pos);
			}
			else
			{
				if (withPS)
					applPath += PATH_SEPARATOR_CHAR;
			}

			return true;
		}
	}

	return false;

#endif

}
Esempio n. 3
0
/*
 * FindNav
 * 임의의 url 을 기준으로 일치하는 데이터를 검색한다.
 * 파라미터	src		찾고자 하는 nav 데이터의 src
 * 리턴값	검색된 nav element
 */
CXMLDOMElement NAVXML::FindNav(const wchar_t* src)
{
	SelectionNamespaces(NAMESPACE_EPUB_W);

	UniString		str;
	str.Format(USTR("//a[@href='%s']"), src);

	CXMLDOMElement docElem = GetDocumentElement();
	return docElem.SelectSingleNode(str);
}
Esempio n. 4
0
bool StartsWith(UniString const & s, UniString const & p)
{
  if (p.size() > s.size())
    return false;
  for (size_t i = 0; i < p.size(); ++i)
  {
    if (s[i] != p[i])
      return false;
  }
  return true;
}
Esempio n. 5
0
void NormalizeDigits(UniString & us)
{
  size_t const size = us.size();
  for (size_t i = 0; i < size; ++i)
  {
    UniChar const c = us[i];
    if (c >= 0xFF10 /* '0' */ && c <= 0xFF19 /* '9' */)
      us[i] = c - 0xFF10 + '0';
  }
}
Esempio n. 6
0
bool
UniString::EndsWith(const UniString& other, size_t length /* = OpDataFullLength */) const
{
	length = MIN(length, other.Length());
	if (length > Length())
		return false;
	if (!length)
		return true;
	return m_data.EndsWith(other.m_data, UNICODE_SIZE(length));
}
bool FSEnsureDirectory(const unicode_t* lpPathName)
{
	int nLen = (int)CH_LENGTH(lpPathName);

	UniString	path;
	for (int i = nLen - 1; i >= 0; i--)
	{
		if (lpPathName[i] == PATH_SEPARATOR_CHAR )
		{
			path.Init(i, lpPathName);

			if ( FSExistFile(path) ) break;

			if (!FSEnsureDirectory(path) )
			{
				return false;
			}
		}
	}

	return  ::FSCreateDirectory(lpPathName);
}
Esempio n. 8
0
bool
UniString::StartsWithCase(const UniString& other, size_t length /* = OpDataFullLength */) const
{
	length = MIN(length, other.Length());
	if (length > Length())
		return false;
	if (!length)
		return true;

	UniStringFragmentIterator this_itr(*this);
	UniStringFragmentIterator other_itr(other);
	size_t this_length = this_itr.GetLength();
	const uni_char* this_data = this_itr.GetData();
	size_t this_str_len = uni_strnlen(this_data, this_length);
	size_t other_length = other_itr.GetLength();
	const uni_char* other_data = other_itr.GetData();
	size_t other_str_len = uni_strnlen(other_data, other_length);
	while (length)
	{
		OP_ASSERT(this_itr && this_data && this_length);
		OP_ASSERT(other_itr && other_data && other_length);

		size_t to_compare = MIN(this_length, length);
		if (to_compare > other_length) to_compare = other_length;
		if (to_compare > this_str_len)
		{
			OP_ASSERT(this_str_len != this_length);
			to_compare = this_str_len;
		}
		if (to_compare > other_str_len)
		{
			OP_ASSERT(other_str_len != other_length);
			to_compare = other_str_len;
		}

		// compare the first part of both fragments
		if (to_compare == 0)
		{
			OP_ASSERT(other_length > 0 && this_length > 0 &&
					  other_str_len != other_length && this_str_len != this_length);
			if (this_str_len != 0 && other_str_len != 0)
				return false;
			OP_ASSERT(this_data[0] == '\0' && other_data[0] == '\0');
			to_compare++;
		}
		else if (0 != uni_strnicmp(this_data, other_data, to_compare))
			return false;

		// advance to the next part to compare:
		length -= to_compare;

		if (length > 0)
		{
			// advance data of this
			this_length -= to_compare;
			if (this_length > 0)
			{
				this_data += to_compare;
				if (this_str_len == 0)
					this_str_len = uni_strnlen(this_data, this_length);
				else
					this_str_len -= to_compare;
			}
			else
			{
				++this_itr;
				this_length = this_itr.GetLength();
				this_data = this_itr.GetData();
				this_str_len = uni_strnlen(this_data, this_length);
			}

			// advance data of other
			other_length -= to_compare;
			if (other_length > 0)
			{
				other_data += to_compare;
				if (other_str_len == 0)
					other_str_len = uni_strnlen(other_data, other_length);
				else
					other_str_len -= to_compare;
			}
			else
			{
				++other_itr;
				other_length = other_itr.GetLength();
				other_data = other_itr.GetData();
				other_str_len = uni_strnlen(other_data, other_length);
			}
		}
	}

	return true;
}
OP_STATUS OpDummyLanguageManager::GetString(Str::LocaleString num, UniString &s)
{
	s.Clear();
	return OpStatus::OK;
}
OP_STATUS HistoryAutocompleteModelItem::ShortenUrlQuery(UniString& text, const OpStringC& preserve, int max_length)
{
	int input_length = text.Length();

	UniString uni_out;

	if (text.FindFirst(UNI_L("&")) == OpDataNotFound || max_length <= SHORTENING_VISIBLE_LENGTH)
	{
		if (max_length > SHORTENING_VISIBLE_LENGTH)
		{
			text.Trunc(max_length - SHORTENING_VISIBLE_LENGTH);
			RETURN_IF_ERROR(text.AppendConstData(UNI_L(SHORTENING),sizeof(SHORTENING)-1));
		}
		else
		{
			text.Trunc(max_length);
		}
	}

	bool add_delimiter = true;

	OpAutoPtr< OtlCountedList<UniString> > parts(text.Split('&'));

	int count = parts->Count();
	for (OtlList<UniString>::Iterator part = parts->Begin(); part != parts->End(); ++part)
	{
		count--;
		if (part->IsEmpty())
			continue;
			
		if (max_length - uni_out.Length() - SHORTENING_VISIBLE_LENGTH <= 0)
			break;

		if (count == 0)
		{
			if (add_delimiter)
				RETURN_IF_ERROR(uni_out.AppendConstData(UNI_L("&"),1));
			RETURN_IF_ERROR(uni_out.Append(*part));
			continue;
		}

		if ((!add_delimiter || part->Length() > SHORTENING_VISIBLE_LENGTH ) &&
			(!preserve.CStr() || part->FindFirst(preserve) == OpDataNotFound) && input_length > (max_length - (int)uni_out.Length()))
		{
			if (!add_delimiter)
			{
				input_length -= part->Length();
				continue;
			}

			RETURN_IF_ERROR(uni_out.AppendConstData(UNI_L(SHORTENING),sizeof(SHORTENING)-1));
			RETURN_IF_ERROR(uni_out.AppendConstData(UNI_L("&"),1));
			
			add_delimiter=false;
			input_length -= part->Length() + 1;
		}
		else
		{
			RETURN_IF_ERROR(uni_out.Append(*part));
			RETURN_IF_ERROR(uni_out.AppendConstData(UNI_L("&"),1));
			
			add_delimiter = true;
			input_length -= part->Length() + 1;
		}
	}

	text = uni_out;

	return OpStatus::OK;
}
Esempio n. 11
0
 // *NOTE* |s| must be not temporary!
 TokenizeIterator(UniString const & s, TDelimFn const & delimFn)
   : m_start(s.begin()), m_end(s.begin()), m_finish(s.end()), m_delimFn(delimFn), m_finished(false)
 {
   while (m_end != m_finish && !m_delimFn(*m_end))
     ++m_end;
 }
Esempio n. 12
0
 // *NOTE* |s| must be not temporary!
 TokenizeIterator(UniString const & s, TDelimFn const & delimFn)
   : m_start(s.begin()), m_end(s.begin()), m_finish(s.end()), m_delimFn(delimFn)
 {
   Move();
 }
Esempio n. 13
0
	void Directory::_VisitDirectory(const String& path, const String& pattern,
		const String& subPath, ScanCallback* callback, bool recursive) {
		FileAttribute attr;

		String fullPath;
		fullPath = path;
		if (subPath.length())
			fullPath = URL::GetAppendedPath(fullPath, subPath);
		else
			fullPath = path;
#if defined(NEX_MSVC)
		if (pattern.length())
			fullPath = URL::GetAppendedPath(fullPath, pattern);

		UniString fullPathUni = StringUtils::ToUtf16(fullPath);
		intptr_t fileHandle, res;
		struct _wfinddata_t data;
		fileHandle = _wfindfirst((const wchar_t*)fullPathUni.c_str(), &data);
		res = 0;
		while (fileHandle != -1 && res != -1) {
			String utf8path = StringUtils::ToUtf8((const char16_t*)data.name);
			String fullPath = URL::GetAppendedPath(path, utf8path);
			attr.fileName = URL(GetName(), URL::GetAppendedPath(subPath, utf8path));
			attr.flags = 0;
			if ((data.attrib & _A_SUBDIR)) {
				if ((!URL::IsReservedPath(utf8path.c_str())) && recursive)
					_VisitDirectory(fullPath, pattern, attr.fileName.GetRelativePath(), callback, true);
				attr.flags = FileAttribute::ATTRIB_DIR;
			}
			else if (data.attrib * _A_ARCH)
				attr.flags = FileAttribute::ATTRIB_ARC;
			if (data.attrib * _A_RDONLY)
				attr.flags |= FileAttribute::ATTRIB_READONLY;
			NEX_SET_FILE_TIME(attr.fileTime, data.time_write);
			attr.compressedSize = data.size;
			attr.uncompressedSize = data.size;
			callback->FoundFile(attr, this);
			res = _wfindnext(fileHandle, &data);
		}

		if (fileHandle != -1)
			_findclose(fileHandle);
#elif defined(NEX_GCC)
		/** todo Fix this */
		DIR *dp;
		struct dirent *dirp;
		fullPath = path + "/" + subPath;

		dp = opendir(fullPath.c_str());
		if (dp) {
			while ((dirp = readdir(dp)) != NULL) {
				if (!pattern.length()
					|| StringUtils::PatternMatch(pattern.c_str(), dirp->d_name,
					true)) {
					String fullPathName = URL::GetAppendedPath(fullPath, dirp->d_name);
					attr.fileName = URL(GetName(),
						URL::GetAppendedPath(subPath, dirp->d_name));
					attr.flags = 0;
					struct stat filestat;
					int ret = stat(fullPathName.c_str(), &filestat);
					if (ret == 0)
						StatToAttribute(filestat, attr);
					callback->FoundFile(attr, this);
					if (recursive && (attr.flags & FileAttribute::ATTRIB_DIR)
						&& !URL::IsReservedPath(dirp->d_name))
						_VisitDirectory(fullPath, pattern,
						attr.fileName.GetRelativePath(), callback,
						true);
				}
			}
			closedir(dp);
		}
#endif
	}
Esempio n. 14
0
void FSAppendPath(UniString &string, const unicode_t *path)
{
	if ( string.GetLastChar() != PATH_SEPARATOR_CHAR )
		string += PATH_SEPARATOR_CHAR;
	string += path;
}
Esempio n. 15
0
void FSDeleteFolderAndFiles(const unicode_t *dirName)
{
	if ( dirName == NULL ) return;
	if ( *dirName == 0 ) return;

#if defined(WIN32) || defined(_WIN32_WCE)

	UniString	findDir(dirName);

	if ( !findDir.EndWith(USTR("\\*.*")) )
	{
		if ( findDir.GetLastChar() == '\\' )
			findDir += L"*.*";
		else
			findDir += L"\\*.*";

		if ( findDir.GetCount() <= 6 ) return;
	}
	else
	{
		if ( findDir.GetCount() <= 6 ) return;
	}

	HANDLE hFind;

#if defined(_WIN32_WCE)
	WIN32_FIND_DATA findFileData;
	hFind = FindFirstFile(findDir.GetString(), &findFileData);
#else
	WIN32_FIND_DATAW findFileData;
	hFind = FindFirstFileW(findDir.GetString(), &findFileData);
#endif

	if (hFind != INVALID_HANDLE_VALUE) 
	{
		UniString	filePath;

		do
		{
			if ( wcscmp(findFileData.cFileName, L".") == 0 || wcscmp(findFileData.cFileName, L"..") == 0 )
				continue;

			filePath = dirName;
			filePath += L"\\";
			filePath += findFileData.cFileName;

			if ( findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
			{
				FSDeleteFolderAndFiles(filePath);
			}
			else
			{
				if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
					SetFileAttributesW(filePath.GetString(), FILE_ATTRIBUTE_NORMAL);

			#if defined(_WIN32_WCE)
				DeleteFile(filePath);
			#else
				DeleteFileW(filePath);
			#endif
			}
		}
	#if defined(_WIN32_WCE)
		while (FindNextFile(hFind, &findFileData) != 0);
	#else
		while (FindNextFileW(hFind, &findFileData) != 0);
	#endif

		FindClose(hFind);
	}

	RemoveDirectoryW(dirName);

#elif defined(__APPLE_CPP__) || defined(__APPLE_CC__)
	FSString	fsString(dirName);
	
	if ( fsString.GetCount() <= 1 ) return;

	_DeleteFolderAndFiles(fsString.GetString());
#else
	FSString	fsString(dirName);
	_DeleteFolderAndFiles(fsString.GetString());
#endif
}
Esempio n. 16
0
string ToUtf8(UniString const & s)
{
  string result;
  utf8::unchecked::utf32to8(s.begin(), s.end(), back_inserter(result));
  return result;
}
Esempio n. 17
0
 /// @warning unistring S must be not temporary!
 TokenizeIterator(UniString const & s, DelimFuncT const & delimFunc)
 : m_beg(s.begin()), m_end(s.begin()), m_finish(s.end()), m_delimFunc(delimFunc)
 {
   move();
 }
Esempio n. 18
0
	bool Directory::GetAttribute(const String& fileName,
		nextar::FileAttribute & attr) {

		String path;
		MultiStringHelper pathsL(paths);
		MultiStringHelper::Iterator it = pathsL.Iterate();
		while (it.HasNext(path)) {
			String fullPath = URL::GetAppendedPath(path, fileName);

#if NEX_WINDOWS==1
			if (StringUtils::IsAscii(fullPath)) {
				struct stat filestat;
				int ret = stat(fullPath.c_str(), &filestat);
				if (ret == 0) {
					attr.fileName = URL(GetName(), fileName);
					attr.flags = 0;
					StatToAttribute(filestat, attr);
				}
				else
					return false;
			}
			else {
				UniString fullPathUni = StringUtils::ToUtf16(fullPath);
				DWORD flags = GetFileAttributesW((const wchar_t*)fullPathUni.c_str());
				if (flags == INVALID_FILE_ATTRIBUTES)
					return false;
				else
					attr.fileName = URL(GetName(), fileName);
				if (flags & FILE_ATTRIBUTE_DIRECTORY)
					attr.flags = FileAttribute::ATTRIB_DIR;
				if ((flags & FILE_ATTRIBUTE_READONLY))
					attr.flags |= FileAttribute::ATTRIB_READONLY;
				if ((flags & FILE_ATTRIBUTE_ARCHIVE))
					attr.flags |= FileAttribute::ATTRIB_ARC;
				if ((flags & FILE_ATTRIBUTE_COMPRESSED))
					attr.flags |= FileAttribute::ATTRIB_COMPRESSED;
				HANDLE hFile = CreateFileW((const wchar_t*)fullPathUni.c_str(), GENERIC_READ,
					FILE_SHARE_READ,
					NULL,
					OPEN_EXISTING,
					0,
					NULL);
				if (hFile != INVALID_HANDLE_VALUE) {
					FILETIME lastWriteTime;
					if (GetFileTime(hFile, NULL, NULL, &lastWriteTime))
						WriteFileTime(attr.fileTime, lastWriteTime);
				}

				attr.uncompressedSize = GetFileSize(hFile, NULL);
				if ((flags & FILE_ATTRIBUTE_COMPRESSED))
					attr.compressedSize = GetCompressedFileSizeW((const wchar_t*)fullPathUni.c_str(), NULL);
			}

#elif NEX_LINUX==1
			struct stat filestat;
			int ret = stat(fullPath.c_str(), &filestat);
			if (ret == 0) {
				attr.fileName = URL(GetName(), fileName);
				attr.flags = 0;
				StatToAttribute(filestat, attr);
			}
			else
				return false;
#else //problem
#	error Platform error
#endif
			return true;
		}
		return false;