Ejemplo n.º 1
0
 inline utf8String wideToUtf8( const wideString& in ) throw()
 {
   int length = WideCharToMultiByte( CP_UTF8, 0, in.c_str(), -1, nullptr, 0, 0, FALSE );
   if ( length == 0 )
     return utf8String();
   vector<char> conversion( length );
   WideCharToMultiByte( CP_UTF8, 0, in.c_str(), -1, &conversion[0], length, 0, FALSE );
   return utf8String( &conversion[0] );
 }
Ejemplo n.º 2
0
void KURLPrivate::replaceComponents(const Replacements& replacements)
{
    url_canon::RawCanonOutputT<char> output;
    url_parse::Parsed newParsed;

    m_isValid = url_util::ReplaceComponents(utf8String().data(), utf8String().length(), m_parsed, replacements, 0, &output, &newParsed);

    m_parsed = newParsed;
    if (m_parsed.ref.is_nonempty())
        setUTF8(CString(output.data(), output.length()));
    else
        setASCII(CString(output.data(), output.length()));
}
nsresult nsAddbookProtocolHandler::GenerateXMLOutputChannel(
    nsString &aOutput, nsIAddbookUrl *addbookUrl, nsIURI *aURI,
    nsILoadInfo *aLoadInfo, nsIChannel **_retval) {
  nsresult rv;
  nsCOMPtr<nsIStringInputStream> inStr(
      do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  NS_ConvertUTF16toUTF8 utf8String(aOutput.get());

  rv = inStr->SetData(utf8String.get(), utf8String.Length());
  NS_ENSURE_SUCCESS(rv, rv);

  if (aLoadInfo) {
    return NS_NewInputStreamChannelInternal(_retval, aURI, inStr.forget(),
                                            NS_LITERAL_CSTRING("text/xml"),
                                            EmptyCString(), aLoadInfo);
  }

  nsCOMPtr<nsIPrincipal> nullPrincipal =
      do_CreateInstance("@mozilla.org/nullprincipal;1", &rv);
  NS_ASSERTION(NS_SUCCEEDED(rv), "CreateInstance of nullprincipalfailed.");
  if (NS_FAILED(rv)) return rv;

  return NS_NewInputStreamChannel(
      _retval, aURI, inStr.forget(), nullPrincipal,
      nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
      nsIContentPolicy::TYPE_OTHER, NS_LITERAL_CSTRING("text/xml"));
}
Ejemplo n.º 4
0
 inline utf8String cleanupName( utf8String name ) throw()
 {
   boost::algorithm::trim_all( name );
   if ( boost::iequals( name, "?" ) )
     return utf8String();
   return name;
 }
Ejemplo n.º 5
0
	void CoerceInstruction::print() {
		char buffer[128];
		char typeOfInstruction[32];
		char coerceResult[32];

		if (this->isConvert()) {
			VMPI_snprintf(typeOfInstruction, sizeof(typeOfInstruction), "ConvertInstruction");
		} else {
			VMPI_snprintf(typeOfInstruction, sizeof(typeOfInstruction), "CoerceInstruction");
		}

		if (this->isMultinameCoerce()) {
			avmplus::Stringp coerceType = this->multinameToCoerce->getName();
			StUTF8String utf8String(coerceType );
			const char* stringValue = utf8String.c_str();
			VMPI_snprintf(coerceResult, sizeof(coerceResult), "%s", stringValue);
		} else {
			VMPI_snprintf(coerceResult, sizeof(coerceResult), "%s", this->getTypeToCoerce()->toString().data());
		}

		VMPI_snprintf(buffer, sizeof(buffer), "%s %s (%s) -> %s", this->getPrintPrefix().c_str(),
			typeOfInstruction, _instructionToCoerce->getOperandString().c_str(), coerceResult);

		printf("%s\n", buffer);
	}
Ejemplo n.º 6
0
void DataInputStream::readUTF8(StringStorage *storage)
{
  UINT32 sizeInBytes = readUInt32();
  if (sizeInBytes > 0) {
    std::vector<char> buffer(sizeInBytes);
    readFully(&buffer.front(), sizeInBytes);
    Utf8StringStorage utf8String(&buffer);
    utf8String.toStringStorage(storage);
  } else {
    storage->setString(_T(""));
  }
}
Ejemplo n.º 7
0
std::string ToUtf8String(const std::wstring& str)
{
  int length = static_cast<int>(str.size());
  if (length == 0)
    return std::string();

  int utf8StringLength = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), length, 0, 0, 0, 0);
  if (utf8StringLength == 0)
    throw std::runtime_error("Failed to determine the required buffer size");

  std::string utf8String(utf8StringLength, '\0');
  WideCharToMultiByte(CP_UTF8, 0, str.c_str(), length, &utf8String[0], utf8StringLength, 0, 0);
  return utf8String;
}
Ejemplo n.º 8
0
bool FSExistFile(const unicode_t *fileName)
{
	if ( fileName == NULL ) return false;
	if ( *fileName == 0 ) return false;

#if defined(_WIN32_WCE)

	return (GetFileAttributes(fileName) != INVALID_FILE_ATTRIBUTES);

#elif defined(WIN32)

//	return PathFileExistsW(fileName);
	return (GetFileAttributesW(fileName) != INVALID_FILE_ATTRIBUTES);
//	return _waccess(fileName, 0) == 0;

#elif defined(__APPLE_CPP__) || defined(__APPLE_CC__)
	FSString	utf8String(fileName);
	return _ExistFile(utf8String.GetString());
#else
	FSString	utf8String(fileName);
	return _ExistFile(utf8String.GetString());
#endif
}
Ejemplo n.º 9
0
String KURLPrivate::componentString(const url_parse::Component& component) const
{
    if (!m_isValid || component.len <= 0) {
        // KURL returns a null string if the URL is itself a null string, and an
        // empty string for other nonexistent entities.
        if (utf8String().isNull())
            return String();
        return String("", 0);
    }
    // begin and len are in terms of bytes which do not match
    // if string() is UTF-16 and input contains non-ASCII characters.
    // However, the only part in urlString that can contain non-ASCII
    // characters is 'ref' at the end of the string. In that case,
    // begin will always match the actual value and len (in terms of
    // byte) will be longer than what's needed by 'mid'. However, mid
    // truncates len to avoid go past the end of a string so that we can
    // get away withtout doing anything here.
    return string().substring(component.begin, component.len);
}
Ejemplo n.º 10
0
/*******************************************************************************
函数名称:				WorkClass::WriteString2File	写字符串内容到文件
================================================================================
参数说明:				const CString strText 文件内容
参数说明:				const CString strSavePath 文件路径
参数说明:				BOOL bUtf_8 是否为UTF-8格式
--------------------------------------------------------------------------------
返回值:					BOOL
--------------------------------------------------------------------------------
文件作者:				King.Sollyu					QQ:191067617
*******************************************************************************/
BOOL WorkClass::WriteString2File( const CString strText,const CString strSavePath,BOOL bUtf_8 )
{
	CFile fileText; CFileException fileException;
	if (fileText.Open(strSavePath,CFile::modeReadWrite|CFile::modeCreate,&fileException) == FALSE)
	{
		ASSERT (FALSE);
		// 打开文件错误,识别什么错误
		switch (fileException.m_cause)
		{
		case CFileException::fileNotFound:	return SetLastError(ERR_FILENOTFOUND),FALSE;break;
		case CFileException::accessDenied:	return SetLastError(ERR_ACCESSDENIED),FALSE;break;
		case CFileException::sharingViolation: return SetLastError(ERR_SHARINGVIOLATION),FALSE;break;
		default:return SetLastError(ERR_UNKNOW),FALSE;break;
		}
	}

	if (bUtf_8 == TRUE)
	{
		unsigned char data[3] = {0xEF, 0xBB, 0xBF};
		fileText.Write(data,3);
		int nSrcLen = (int)wcslen(strText);
		CStringA utf8String(strText);
		int nBufLen = (nSrcLen+1) * 6;
		LPSTR buffer = utf8String.GetBufferSetLength(nBufLen);
		// 将UNICODE 转换成UTF8
		// 需要函数AtlUnicodeToUTF8 头文件: <atlenc.h>
		int nLen = AtlUnicodeToUTF8(strText, nSrcLen, buffer, nBufLen);   
		buffer[nLen] = 0;
		utf8String.ReleaseBuffer();
		//写文件
		fileText.SeekToEnd();
		fileText.Write((LPCSTR)utf8String, nLen);
	}else
	{
		CStringA strANSI(strText);
		fileText.Write((LPCSTR)strANSI,strANSI.GetLength());
	}

	fileText.Close();
	return TRUE;

}
nsresult
nsAddbookProtocolHandler::GenerateXMLOutputChannel( nsString &aOutput,
        nsIAddbookUrl *addbookUrl,
        nsIURI *aURI,
        nsIChannel **_retval)
{
    nsIChannel                *channel;
    nsresult rv;
    nsCOMPtr<nsIStringInputStream> inStr(do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    NS_ConvertUTF16toUTF8 utf8String(aOutput.get());

    rv = inStr->SetData(utf8String.get(), utf8String.Length());

    rv = NS_NewInputStreamChannel(&channel, aURI, inStr,
                                  NS_LITERAL_CSTRING("text/xml"));
    NS_ENSURE_SUCCESS(rv, rv);

    *_retval = channel;
    return rv;
}
Ejemplo n.º 12
0
bool ODe_AbiDocListener::populate(PL_StruxFmtHandle /*sfh*/,
                                 const PX_ChangeRecord * pcr)
{
    switch (pcr->getType()) {
        
    case PX_ChangeRecord::PXT_InsertSpan:
    {
        const PX_ChangeRecord_Span * pcrs =
            static_cast<const PX_ChangeRecord_Span *> (pcr);
            
        if (pcrs->getField()!=m_pCurrentField) {
            _closeField();
        }
        
        PT_AttrPropIndex api = pcr->getIndexAP();
        _openSpan(api);

        PT_BufIndex bi = pcrs->getBufIndex();
        
        UT_UTF8String utf8String (m_pDocument->getPointer(bi),
                                    pcrs->getLength());
                        
        _outputData(m_pDocument->getPointer(bi), pcrs->getLength());
    }
    break;
        
    case PX_ChangeRecord::PXT_InsertObject:
        {
            const PX_ChangeRecord_Object * pcro =
                static_cast<const PX_ChangeRecord_Object *> (pcr);
                
            PT_AttrPropIndex api = pcr->getIndexAP();
            switch (pcro->getObjectType())
            {
            case PTO_Image:
                {
                    _closeSpan();
                    _closeField();
                    _insertInlinedImage(api);
                    return true;
                }
                
            case PTO_Field:
                {
                    _closeSpan();
                    _closeField();
                    _openField(pcro, api);
                    return true;
                }
                
            case PTO_Math:
                {
                    _closeSpan();
                    _closeField();
                    _insertMath(api);
                    return true;
                }
                
            case PTO_Embed:
                {
                    //TODO: we may want to save the actual chart xml one day,
                    // but saving the image will do for now
                    _closeSpan();
                    _closeField();
                    _insertEmbeddedImage(api);
                    return true;
                }
                
            case PTO_Bookmark:
                {
                    _closeSpan();
                    _closeField();

                    const PP_AttrProp* pAP = NULL;
                    m_pDocument->getAttrProp(api,&pAP);
                    const gchar* pValue = NULL;

                    if(pAP && pAP->getAttribute("type",pValue) && pValue && (strcmp(pValue, "start") == 0)) {
                        _openBookmark(api);
                    } else {
                        _closeBookmark(api);
                    }

                    return true;
                }

            case PTO_Hyperlink:
                {
                    _closeSpan();
                    _closeField();
                    const PP_AttrProp* pAP = NULL;
                    m_pDocument->getAttrProp(api,&pAP);
                    const gchar* pValue = NULL;

                    if(pAP && pAP->getAttribute("xlink:href",pValue) && pValue) {
                        _openHyperlink(api);
                    } else {
                        _closeHyperlink();
                    }
                    
                    return true;
                }

            case PTO_Annotation:
                {
                    _closeSpan();
                    _closeField();
                    return true;
                }

            default:
                UT_ASSERT_HARMLESS(UT_TODO);
                return true;
            }
        }
        
    case PX_ChangeRecord::PXT_InsertFmtMark:
        // fmt marks are temporary placeholders for props and
        // attributes and should not be saved
        return true;

    default:
      UT_ASSERT_HARMLESS(UT_TODO);
        return true;
    }

    
    return true;
}
Ejemplo n.º 13
0
//-----------------------------------------------------------------------------
STDMETHODIMP Win32DataObject::GetData (FORMATETC* format, STGMEDIUM* medium)
{
	medium->tymed = 0;
	medium->hGlobal = 0;
	medium->pUnkForRelease = 0;

	if (format->cfFormat == CF_TEXT || format->cfFormat == CF_UNICODETEXT)
	{
		for (int32_t i = 0; i < dataPackage->getCount (); i++)
		{
			if (dataPackage->getDataType (i) == IDataPackage::kText)
			{
				const void* buffer;
				IDataPackage::Type type;
				int32_t bufferSize = dataPackage->getData (i, buffer, type);
				UTF8StringHelper utf8String ((const char*)buffer);
				SIZE_T size = 0;
				const void* data = 0;
				if (format->cfFormat == CF_UNICODETEXT)
				{
					size = bufferSize * sizeof (WCHAR);
					data = utf8String.getWideString ();
				}
				else
				{
					size = bufferSize * sizeof (char);
					data = buffer;
				}
				if (data && size > 0)
				{
					HGLOBAL	memoryHandle = GlobalAlloc (GMEM_MOVEABLE, size); 
					void* memory = GlobalLock (memoryHandle);
					if (memory)
					{
						memcpy (memory, data, size);
						GlobalUnlock (memoryHandle);
					}

					medium->hGlobal = memoryHandle;						
					medium->tymed = TYMED_HGLOBAL;
					return S_OK;
				}
			}
		}
	}
	else if (format->cfFormat == CF_HDROP)
	{
		HRESULT result = E_UNEXPECTED;
		UTF8StringHelper** wideStringFileNames = (UTF8StringHelper**)malloc (sizeof (UTF8StringHelper*) * dataPackage->getCount ());
		memset (wideStringFileNames, 0, sizeof (UTF8StringHelper*) * dataPackage->getCount ());
		int32_t fileNamesIndex = 0;
		int32_t bufferSizeNeeded = 0;
		for (int32_t i = 0; i < dataPackage->getCount (); i++)
		{
			if (dataPackage->getDataType (i) == IDataPackage::kFilePath)
			{
				const void* buffer;
				IDataPackage::Type type;
				int32_t bufferSize = dataPackage->getData (i, buffer, type);

				wideStringFileNames[fileNamesIndex] = new UTF8StringHelper ((UTF8StringPtr)buffer);
				bufferSizeNeeded += (int32_t)wcslen (*wideStringFileNames[fileNamesIndex]) + 1;
				fileNamesIndex++;
			}
		}
		bufferSizeNeeded++;
		bufferSizeNeeded *= sizeof (WCHAR);
		bufferSizeNeeded += sizeof (DROPFILES);
		HGLOBAL	memoryHandle = GlobalAlloc (GMEM_MOVEABLE, bufferSizeNeeded); 
		void* memory = GlobalLock (memoryHandle);
		if (memory)
		{
			DROPFILES* dropFiles = (DROPFILES*)memory;
			dropFiles->pFiles = sizeof (DROPFILES);
			dropFiles->pt.x   = 0; 
			dropFiles->pt.y   = 0;
			dropFiles->fNC    = FALSE;
			dropFiles->fWide  = TRUE;
			int8_t* memAddr = ((int8_t*)memory) + sizeof (DROPFILES);
			for (int32_t i = 0; i < fileNamesIndex; i++)
			{
				size_t len = (wcslen (wideStringFileNames[i]->getWideString ()) + 1) * 2;
				memcpy (memAddr, wideStringFileNames[i]->getWideString (), len);
				memAddr += len;
			}
			*memAddr = 0;
			memAddr++;
			*memAddr = 0;
			memAddr++;
			GlobalUnlock (memoryHandle);
			medium->hGlobal = memoryHandle;
			medium->tymed = TYMED_HGLOBAL;
			result = S_OK;
		}
		for (int32_t i = 0; i < fileNamesIndex; i++)
			delete wideStringFileNames[i];
		free (wideStringFileNames);
		return result;
	}
	else if (format->cfFormat == CF_PRIVATEFIRST)
	{
		for (int32_t i = 0; i < dataPackage->getCount (); i++)
		{
			if (dataPackage->getDataType (i) == IDataPackage::kBinary)
			{
				const void* buffer;
				IDataPackage::Type type;
				int32_t bufferSize = dataPackage->getData (i, buffer, type);

				HGLOBAL	memoryHandle = GlobalAlloc (GMEM_MOVEABLE, bufferSize); 
				void* memory = GlobalLock (memoryHandle);
				if (memory)
				{
					memcpy (memory, buffer, bufferSize);
					GlobalUnlock (memoryHandle);
				}

				medium->hGlobal = memoryHandle;						
				medium->tymed = TYMED_HGLOBAL;
				return S_OK;
			}
		}
	}

	return E_UNEXPECTED;
}