2015-04-09 20:25:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCharTraits.h"
|
|
|
|
|
2006-05-03 20:11:14 +04:00
|
|
|
#include "nsXPCOMStrings.h"
|
2004-04-02 00:47:48 +04:00
|
|
|
#include "nsNativeCharsetUtils.h"
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
2005-11-08 21:17:49 +03:00
|
|
|
XPCOM_API(nsresult)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_StringContainerInit(nsStringContainer& aContainer)
|
2004-02-19 05:44:03 +03:00
|
|
|
{
|
2006-05-03 20:34:24 +04:00
|
|
|
NS_ASSERTION(sizeof(nsStringContainer_base) >= sizeof(nsString),
|
2014-08-13 22:45:37 +04:00
|
|
|
"nsStringContainer is not large enough");
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
// use placement new to avoid heap allocating nsString object
|
|
|
|
new (&aContainer) nsString();
|
|
|
|
|
2004-04-12 00:52:32 +04:00
|
|
|
return NS_OK;
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
2005-11-08 21:17:49 +03:00
|
|
|
XPCOM_API(nsresult)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_StringContainerInit2(nsStringContainer& aContainer,
|
|
|
|
const char16_t* aData,
|
|
|
|
uint32_t aDataLength,
|
|
|
|
uint32_t aFlags)
|
2004-11-16 07:44:57 +03:00
|
|
|
{
|
2006-05-03 20:34:24 +04:00
|
|
|
NS_ASSERTION(sizeof(nsStringContainer_base) >= sizeof(nsString),
|
2014-08-13 22:45:37 +04:00
|
|
|
"nsStringContainer is not large enough");
|
2004-11-16 07:44:57 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
if (!aData) {
|
2004-11-16 07:44:57 +03:00
|
|
|
new (&aContainer) nsString();
|
2014-08-13 22:45:37 +04:00
|
|
|
} else {
|
|
|
|
if (aDataLength == UINT32_MAX) {
|
|
|
|
if (NS_WARN_IF(aFlags & NS_STRING_CONTAINER_INIT_SUBSTRING)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2014-01-04 19:02:17 +04:00
|
|
|
aDataLength = nsCharTraits<char16_t>::length(aData);
|
2004-11-16 07:44:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aFlags & (NS_STRING_CONTAINER_INIT_DEPEND |
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_STRING_CONTAINER_INIT_ADOPT)) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags;
|
2014-08-13 22:45:37 +04:00
|
|
|
if (aFlags & NS_STRING_CONTAINER_INIT_SUBSTRING) {
|
2004-11-16 07:44:57 +03:00
|
|
|
flags = nsSubstring::F_NONE;
|
2014-08-13 22:45:37 +04:00
|
|
|
} else {
|
2004-11-16 07:44:57 +03:00
|
|
|
flags = nsSubstring::F_TERMINATED;
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
2004-11-16 07:44:57 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
if (aFlags & NS_STRING_CONTAINER_INIT_ADOPT) {
|
2004-11-16 07:44:57 +03:00
|
|
|
flags |= nsSubstring::F_OWNED;
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
2004-11-16 07:44:57 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
new (&aContainer) nsSubstring(const_cast<char16_t*>(aData),
|
2004-11-16 07:44:57 +03:00
|
|
|
aDataLength, flags);
|
2014-08-13 22:45:37 +04:00
|
|
|
} else {
|
2004-11-16 07:44:57 +03:00
|
|
|
new (&aContainer) nsString(aData, aDataLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-11-08 21:17:49 +03:00
|
|
|
XPCOM_API(void)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_StringContainerFinish(nsStringContainer& aContainer)
|
2004-02-19 05:44:03 +03:00
|
|
|
{
|
|
|
|
// call the nsString dtor
|
2014-08-13 22:45:37 +04:00
|
|
|
reinterpret_cast<nsString*>(&aContainer)->~nsString();
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
XPCOM_API(uint32_t)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_StringGetData(const nsAString& aStr, const char16_t** aData,
|
|
|
|
bool* aTerminated)
|
2004-02-19 05:44:03 +03:00
|
|
|
{
|
2014-08-13 22:45:37 +04:00
|
|
|
if (aTerminated) {
|
2004-02-19 05:44:03 +03:00
|
|
|
*aTerminated = aStr.IsTerminated();
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2016-09-30 05:33:57 +03:00
|
|
|
*aData = aStr.BeginReading();
|
|
|
|
return aStr.Length();
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
XPCOM_API(uint32_t)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_StringGetMutableData(nsAString& aStr, uint32_t aDataLength,
|
|
|
|
char16_t** aData)
|
2005-04-27 05:38:35 +04:00
|
|
|
{
|
2012-09-28 10:57:33 +04:00
|
|
|
if (aDataLength != UINT32_MAX) {
|
2005-04-27 05:38:35 +04:00
|
|
|
aStr.SetLength(aDataLength);
|
|
|
|
if (aStr.Length() != aDataLength) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aData = nullptr;
|
2005-04-27 05:38:35 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-30 05:33:57 +03:00
|
|
|
*aData = aStr.BeginWriting();
|
|
|
|
return aStr.Length();
|
2005-04-27 05:38:35 +04:00
|
|
|
}
|
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
XPCOM_API(char16_t*)
|
|
|
|
NS_StringCloneData(const nsAString& aStr)
|
2004-04-20 04:21:34 +04:00
|
|
|
{
|
|
|
|
return ToNewUnicode(aStr);
|
|
|
|
}
|
|
|
|
|
2005-11-08 21:17:49 +03:00
|
|
|
XPCOM_API(nsresult)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_StringSetData(nsAString& aStr, const char16_t* aData, uint32_t aDataLength)
|
2004-02-19 05:44:03 +03:00
|
|
|
{
|
|
|
|
aStr.Assign(aData, aDataLength);
|
2004-04-12 00:52:32 +04:00
|
|
|
return NS_OK; // XXX report errors
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
2005-11-08 21:17:49 +03:00
|
|
|
XPCOM_API(nsresult)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_StringSetDataRange(nsAString& aStr,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aCutOffset, uint32_t aCutLength,
|
2014-08-13 22:45:37 +04:00
|
|
|
const char16_t* aData, uint32_t aDataLength)
|
2004-02-19 05:44:03 +03:00
|
|
|
{
|
2014-08-13 22:45:37 +04:00
|
|
|
if (aCutOffset == UINT32_MAX) {
|
2004-02-19 05:44:03 +03:00
|
|
|
// append case
|
2014-08-13 22:45:37 +04:00
|
|
|
if (aData) {
|
2004-02-19 05:44:03 +03:00
|
|
|
aStr.Append(aData, aDataLength);
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
2004-04-12 00:52:32 +04:00
|
|
|
return NS_OK; // XXX report errors
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
if (aCutLength == UINT32_MAX) {
|
2004-02-19 05:44:03 +03:00
|
|
|
aCutLength = aStr.Length() - aCutOffset;
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
if (aData) {
|
|
|
|
if (aDataLength == UINT32_MAX) {
|
2004-02-19 05:44:03 +03:00
|
|
|
aStr.Replace(aCutOffset, aCutLength, nsDependentString(aData));
|
2014-08-13 22:45:37 +04:00
|
|
|
} else {
|
2011-12-09 12:35:41 +04:00
|
|
|
aStr.Replace(aCutOffset, aCutLength, Substring(aData, aDataLength));
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
|
|
|
} else {
|
2004-02-19 05:44:03 +03:00
|
|
|
aStr.Cut(aCutOffset, aCutLength);
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
2004-04-12 00:52:32 +04:00
|
|
|
|
|
|
|
return NS_OK; // XXX report errors
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
2005-11-08 21:17:49 +03:00
|
|
|
XPCOM_API(nsresult)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_StringCopy(nsAString& aDest, const nsAString& aSrc)
|
2004-02-19 05:44:03 +03:00
|
|
|
{
|
|
|
|
aDest.Assign(aSrc);
|
2004-04-12 00:52:32 +04:00
|
|
|
return NS_OK; // XXX report errors
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
2007-08-18 07:48:16 +04:00
|
|
|
XPCOM_API(void)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_StringSetIsVoid(nsAString& aStr, const bool aIsVoid)
|
2007-08-18 07:48:16 +04:00
|
|
|
{
|
|
|
|
aStr.SetIsVoid(aIsVoid);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
XPCOM_API(bool)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_StringGetIsVoid(const nsAString& aStr)
|
2007-08-18 07:48:16 +04:00
|
|
|
{
|
|
|
|
return aStr.IsVoid();
|
|
|
|
}
|
|
|
|
|
2004-02-19 05:44:03 +03:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
2005-11-08 21:17:49 +03:00
|
|
|
XPCOM_API(nsresult)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_CStringContainerInit(nsCStringContainer& aContainer)
|
2004-02-19 05:44:03 +03:00
|
|
|
{
|
2006-05-03 20:34:24 +04:00
|
|
|
NS_ASSERTION(sizeof(nsStringContainer_base) >= sizeof(nsCString),
|
2014-08-13 22:45:37 +04:00
|
|
|
"nsCStringContainer is not large enough");
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
// use placement new to avoid heap allocating nsCString object
|
|
|
|
new (&aContainer) nsCString();
|
|
|
|
|
2004-04-12 00:52:32 +04:00
|
|
|
return NS_OK;
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
2005-11-08 21:17:49 +03:00
|
|
|
XPCOM_API(nsresult)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_CStringContainerInit2(nsCStringContainer& aContainer,
|
|
|
|
const char* aData,
|
|
|
|
uint32_t aDataLength,
|
|
|
|
uint32_t aFlags)
|
2004-11-16 07:44:57 +03:00
|
|
|
{
|
2006-05-03 20:34:24 +04:00
|
|
|
NS_ASSERTION(sizeof(nsStringContainer_base) >= sizeof(nsCString),
|
2014-08-13 22:45:37 +04:00
|
|
|
"nsStringContainer is not large enough");
|
2004-11-16 07:44:57 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
if (!aData) {
|
2004-11-16 07:44:57 +03:00
|
|
|
new (&aContainer) nsCString();
|
2014-08-13 22:45:37 +04:00
|
|
|
} else {
|
|
|
|
if (aDataLength == UINT32_MAX) {
|
|
|
|
if (NS_WARN_IF(aFlags & NS_CSTRING_CONTAINER_INIT_SUBSTRING)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2004-11-16 07:44:57 +03:00
|
|
|
aDataLength = nsCharTraits<char>::length(aData);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aFlags & (NS_CSTRING_CONTAINER_INIT_DEPEND |
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_CSTRING_CONTAINER_INIT_ADOPT)) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags;
|
2014-08-13 22:45:37 +04:00
|
|
|
if (aFlags & NS_CSTRING_CONTAINER_INIT_SUBSTRING) {
|
2004-11-16 07:44:57 +03:00
|
|
|
flags = nsCSubstring::F_NONE;
|
2014-08-13 22:45:37 +04:00
|
|
|
} else {
|
2004-11-16 07:44:57 +03:00
|
|
|
flags = nsCSubstring::F_TERMINATED;
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
2004-11-16 07:44:57 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
if (aFlags & NS_CSTRING_CONTAINER_INIT_ADOPT) {
|
2004-11-16 07:44:57 +03:00
|
|
|
flags |= nsCSubstring::F_OWNED;
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
2004-11-16 07:44:57 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
new (&aContainer) nsCSubstring(const_cast<char*>(aData),
|
2004-11-16 07:44:57 +03:00
|
|
|
aDataLength, flags);
|
2014-08-13 22:45:37 +04:00
|
|
|
} else {
|
2004-11-16 07:44:57 +03:00
|
|
|
new (&aContainer) nsCString(aData, aDataLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-11-08 21:17:49 +03:00
|
|
|
XPCOM_API(void)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_CStringContainerFinish(nsCStringContainer& aContainer)
|
2004-02-19 05:44:03 +03:00
|
|
|
{
|
|
|
|
// call the nsCString dtor
|
2014-08-13 22:45:37 +04:00
|
|
|
reinterpret_cast<nsCString*>(&aContainer)->~nsCString();
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
XPCOM_API(uint32_t)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_CStringGetData(const nsACString& aStr, const char** aData,
|
|
|
|
bool* aTerminated)
|
2004-02-19 05:44:03 +03:00
|
|
|
{
|
2014-08-13 22:45:37 +04:00
|
|
|
if (aTerminated) {
|
2004-02-19 05:44:03 +03:00
|
|
|
*aTerminated = aStr.IsTerminated();
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2016-09-30 05:33:57 +03:00
|
|
|
*aData = aStr.BeginReading();
|
|
|
|
return aStr.Length();
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
XPCOM_API(uint32_t)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_CStringGetMutableData(nsACString& aStr, uint32_t aDataLength, char** aData)
|
2005-04-27 05:38:35 +04:00
|
|
|
{
|
2012-09-28 10:57:33 +04:00
|
|
|
if (aDataLength != UINT32_MAX) {
|
2005-04-27 05:38:35 +04:00
|
|
|
aStr.SetLength(aDataLength);
|
|
|
|
if (aStr.Length() != aDataLength) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aData = nullptr;
|
2005-04-27 05:38:35 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-30 05:33:57 +03:00
|
|
|
*aData = aStr.BeginWriting();
|
|
|
|
return aStr.Length();
|
2005-04-27 05:38:35 +04:00
|
|
|
}
|
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
XPCOM_API(char*)
|
|
|
|
NS_CStringCloneData(const nsACString& aStr)
|
2004-04-20 04:21:34 +04:00
|
|
|
{
|
|
|
|
return ToNewCString(aStr);
|
|
|
|
}
|
|
|
|
|
2005-11-08 21:17:49 +03:00
|
|
|
XPCOM_API(nsresult)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_CStringSetData(nsACString& aStr, const char* aData, uint32_t aDataLength)
|
2004-02-19 05:44:03 +03:00
|
|
|
{
|
|
|
|
aStr.Assign(aData, aDataLength);
|
2004-04-12 00:52:32 +04:00
|
|
|
return NS_OK; // XXX report errors
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
2005-11-08 21:17:49 +03:00
|
|
|
XPCOM_API(nsresult)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_CStringSetDataRange(nsACString& aStr,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aCutOffset, uint32_t aCutLength,
|
2014-08-13 22:45:37 +04:00
|
|
|
const char* aData, uint32_t aDataLength)
|
2004-02-19 05:44:03 +03:00
|
|
|
{
|
2014-08-13 22:45:37 +04:00
|
|
|
if (aCutOffset == UINT32_MAX) {
|
2004-02-19 05:44:03 +03:00
|
|
|
// append case
|
2014-08-13 22:45:37 +04:00
|
|
|
if (aData) {
|
2004-02-19 05:44:03 +03:00
|
|
|
aStr.Append(aData, aDataLength);
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
2004-04-12 00:52:32 +04:00
|
|
|
return NS_OK; // XXX report errors
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
if (aCutLength == UINT32_MAX) {
|
2004-02-19 05:44:03 +03:00
|
|
|
aCutLength = aStr.Length() - aCutOffset;
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
if (aData) {
|
|
|
|
if (aDataLength == UINT32_MAX) {
|
2004-02-19 05:44:03 +03:00
|
|
|
aStr.Replace(aCutOffset, aCutLength, nsDependentCString(aData));
|
2014-08-13 22:45:37 +04:00
|
|
|
} else {
|
2011-12-09 12:35:41 +04:00
|
|
|
aStr.Replace(aCutOffset, aCutLength, Substring(aData, aDataLength));
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
|
|
|
} else {
|
2004-02-19 05:44:03 +03:00
|
|
|
aStr.Cut(aCutOffset, aCutLength);
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
2004-04-12 00:52:32 +04:00
|
|
|
|
|
|
|
return NS_OK; // XXX report errors
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
2005-11-08 21:17:49 +03:00
|
|
|
XPCOM_API(nsresult)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_CStringCopy(nsACString& aDest, const nsACString& aSrc)
|
2004-02-19 05:44:03 +03:00
|
|
|
{
|
|
|
|
aDest.Assign(aSrc);
|
2004-04-12 00:52:32 +04:00
|
|
|
return NS_OK; // XXX report errors
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
2004-04-02 00:47:48 +04:00
|
|
|
|
2007-08-18 07:48:16 +04:00
|
|
|
XPCOM_API(void)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_CStringSetIsVoid(nsACString& aStr, const bool aIsVoid)
|
2007-08-18 07:48:16 +04:00
|
|
|
{
|
|
|
|
aStr.SetIsVoid(aIsVoid);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
XPCOM_API(bool)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_CStringGetIsVoid(const nsACString& aStr)
|
2007-08-18 07:48:16 +04:00
|
|
|
{
|
|
|
|
return aStr.IsVoid();
|
|
|
|
}
|
|
|
|
|
2004-04-02 00:47:48 +04:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
2005-11-08 21:17:49 +03:00
|
|
|
XPCOM_API(nsresult)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_CStringToUTF16(const nsACString& aSrc,
|
2004-04-12 00:52:32 +04:00
|
|
|
nsCStringEncoding aSrcEncoding,
|
2014-08-13 22:45:37 +04:00
|
|
|
nsAString& aDest)
|
2004-04-02 00:47:48 +04:00
|
|
|
{
|
2014-08-13 22:45:37 +04:00
|
|
|
switch (aSrcEncoding) {
|
2004-04-12 00:52:32 +04:00
|
|
|
case NS_CSTRING_ENCODING_ASCII:
|
2004-04-02 00:47:48 +04:00
|
|
|
CopyASCIItoUTF16(aSrc, aDest);
|
|
|
|
break;
|
2004-04-12 00:52:32 +04:00
|
|
|
case NS_CSTRING_ENCODING_UTF8:
|
2004-04-02 00:47:48 +04:00
|
|
|
CopyUTF8toUTF16(aSrc, aDest);
|
|
|
|
break;
|
2004-04-12 00:52:32 +04:00
|
|
|
case NS_CSTRING_ENCODING_NATIVE_FILESYSTEM:
|
2004-04-02 00:47:48 +04:00
|
|
|
NS_CopyNativeToUnicode(aSrc, aDest);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2004-04-12 00:52:32 +04:00
|
|
|
return NS_OK; // XXX report errors
|
2004-04-02 00:47:48 +04:00
|
|
|
}
|
|
|
|
|
2005-11-08 21:17:49 +03:00
|
|
|
XPCOM_API(nsresult)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_UTF16ToCString(const nsAString& aSrc,
|
2004-04-12 00:52:32 +04:00
|
|
|
nsCStringEncoding aDestEncoding,
|
2014-08-13 22:45:37 +04:00
|
|
|
nsACString& aDest)
|
2004-04-02 00:47:48 +04:00
|
|
|
{
|
2014-08-13 22:45:37 +04:00
|
|
|
switch (aDestEncoding) {
|
2004-04-12 00:52:32 +04:00
|
|
|
case NS_CSTRING_ENCODING_ASCII:
|
2004-04-02 00:47:48 +04:00
|
|
|
LossyCopyUTF16toASCII(aSrc, aDest);
|
|
|
|
break;
|
2004-04-12 00:52:32 +04:00
|
|
|
case NS_CSTRING_ENCODING_UTF8:
|
2004-04-02 00:47:48 +04:00
|
|
|
CopyUTF16toUTF8(aSrc, aDest);
|
|
|
|
break;
|
2004-04-12 00:52:32 +04:00
|
|
|
case NS_CSTRING_ENCODING_NATIVE_FILESYSTEM:
|
2004-04-02 00:47:48 +04:00
|
|
|
NS_CopyUnicodeToNative(aSrc, aDest);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2004-04-12 00:52:32 +04:00
|
|
|
return NS_OK; // XXX report errors
|
2004-04-02 00:47:48 +04:00
|
|
|
}
|