PRInt32
nsAString::Compare(const self_type &other, ComparatorFunc c) const
{
  const char_type *cself, *cother;
  PRUint32 selflen = NS_StringGetData(*this, &cself);
  PRUint32 otherlen = NS_StringGetData(other, &cother);
  PRUint32 comparelen = selflen <= otherlen ? selflen : otherlen;

  PRInt32 result = c(cself, cother, comparelen);
  if (result == 0) {
    if (selflen < otherlen)
      return -1;
    else if (selflen > otherlen)
      return 1;
  }
  return result;
}
uint32_t
nsAString::BeginReading(const char_type **begin, const char_type **end) const
{
  uint32_t len = NS_StringGetData(*this, begin);
  if (end)
    *end = *begin + len;

  return len;
}
Exemple #3
0
int32_t
nsAString::Compare(const self_type& aOther, ComparatorFunc aComparator) const
{
  const char_type* cself;
  const char_type* cother;
  uint32_t selflen = NS_StringGetData(*this, &cself);
  uint32_t otherlen = NS_StringGetData(aOther, &cother);
  uint32_t comparelen = selflen <= otherlen ? selflen : otherlen;

  int32_t result = aComparator(cself, cother, comparelen);
  if (result == 0) {
    if (selflen < otherlen) {
      return -1;
    } else if (selflen > otherlen) {
      return 1;
    }
  }
  return result;
}
Exemple #4
0
uint32_t
nsAString::BeginReading(const char_type** aBegin, const char_type** aEnd) const
{
  uint32_t len = NS_StringGetData(*this, aBegin);
  if (aEnd) {
    *aEnd = *aBegin + len;
  }

  return len;
}
Exemple #5
0
void
ToUpperCase(const nsAString& aSource,
            nsAString& aDest)
{
  const char16_t *in;
  char16_t *out;
  uint32_t len = NS_StringGetData(aSource, &in);
  NS_StringGetMutableData(aDest, len, &out);
  NS_ASSERTION(out, "Uh...");
  ToUpperCase(in, out, len);
}
void
ToUpperCase(const nsAString& aSource,
            nsAString& aDest)
{
  const PRUnichar *in;
  PRUnichar *out;
  PRUint32 len = NS_StringGetData(aSource, &in);
  NS_StringGetMutableData(aDest, len, &out);
  NS_ASSERTION(out, "Uh...");
  ToUpperCase(in, out, len);
}
Exemple #7
0
PRBool
nsAString::Equals(const char_type *other, ComparatorFunc c) const
{
  const char_type *cself;
  PRUint32 selflen = NS_StringGetData(*this, &cself);
  PRUint32 otherlen = NS_strlen(other);

  if (selflen != otherlen)
    return PR_FALSE;

  return c(cself, other, selflen) == 0;
}
bool
nsAString::Equals(const char_type *other, ComparatorFunc c) const
{
  const char_type *cself;
  uint32_t selflen = NS_StringGetData(*this, &cself);
  uint32_t otherlen = NS_strlen(other);

  if (selflen != otherlen)
    return false;

  return c(cself, other, selflen) == 0;
}
NS_IMETHODIMP
nsJSON::LegacyDecode(const nsAString& json, JSContext* cx, JS::Value* aRetval)
{
  const PRUnichar *data;
  uint32_t len = NS_StringGetData(json, &data);
  nsCOMPtr<nsIInputStream> stream;
  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream),
                                      (const char*) data,
                                      len * sizeof(PRUnichar),
                                      NS_ASSIGNMENT_DEPEND);
  NS_ENSURE_SUCCESS(rv, rv);
  return DecodeInternal(cx, stream, len, false, aRetval, LEGACY);
}
Exemple #10
0
NS_IMETHODIMP
nsJSON::Decode(const nsAString& json)
{
  const PRUnichar *data;
  PRUint32 len = NS_StringGetData(json, &data);
  nsCOMPtr<nsIInputStream> stream;
  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream),
                                      (const char*) data,
                                      len * sizeof(PRUnichar),
                                      NS_ASSIGNMENT_DEPEND);
  NS_ENSURE_SUCCESS(rv, rv);
  return DecodeInternal(stream, len, PR_FALSE);
}
Exemple #11
0
bool
nsAString::Equals(const char_type* aOther, ComparatorFunc aComparator) const
{
  const char_type* cself;
  uint32_t selflen = NS_StringGetData(*this, &cself);
  uint32_t otherlen = NS_strlen(aOther);

  if (selflen != otherlen) {
    return false;
  }

  return aComparator(cself, aOther, selflen) == 0;
}
nsDependentSubstring::nsDependentSubstring(const abstract_string_type& aStr,
                                           uint32_t aStartPos)
{
  const PRUnichar* data;
  uint32_t len = NS_StringGetData(aStr, &data);

  if (aStartPos > len)
    aStartPos = len;

  NS_StringContainerInit2(*this, data + aStartPos, len - aStartPos,
                          NS_STRING_CONTAINER_INIT_DEPEND |
                          NS_STRING_CONTAINER_INIT_SUBSTRING);
}
static void TestEntityConversion(uint32_t version)
{
  printf("==============================\n");
  printf("Start nsIEntityConverter Test \n");
  printf("==============================\n");

  uint32_t i;
  nsString inString;
  PRUnichar uChar;
  nsresult res;


  inString.Assign(NS_ConvertASCIItoUTF16("\xA0\xA1\xA2\xA3"));
  uChar = (PRUnichar) 8364; //euro
  inString.Append(&uChar, 1);
  uChar = (PRUnichar) 9830; //
  inString.Append(&uChar, 1);

  nsCOMPtr <nsIEntityConverter> entityConv = do_CreateInstance(kEntityConverterCID, &res);;
  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n"); return;}

  const PRUnichar *data;
  uint32_t length = NS_StringGetData(inString, &data);

  // convert char by char
  for (i = 0; i < length; i++) {
    char *entity = nullptr;
    res = entityConv->ConvertToEntity(data[i], version, &entity);
    if (NS_SUCCEEDED(res) && entity) {
      printf("%c %s\n", data[i], entity);
      nsMemory::Free(entity);
    }
  }

  // convert at once as a string
  PRUnichar *entities;
  res = entityConv->ConvertToEntities(inString.get(), version, &entities);
  if (NS_SUCCEEDED(res) && entities) {
    for (PRUnichar *centity = entities; *centity; ++centity) {
      printf("%c", (char) *centity);
      if (';' == (char) *centity)
        printf("\n");
    }
    nsMemory::Free(entities);
  }

  printf("==============================\n");
  printf("Finish nsIEntityConverter Test \n");
  printf("==============================\n\n");
}
Exemple #14
0
wxString ns2wx(nsEmbedString& str)
{
    wxString res;
    const PRUnichar* begin;
    const PRUnichar* end;
    
    PRUint32 i, len = NS_StringGetData(str, &begin);
    end = begin + len;
    
    res.Alloc(end - begin);
    for (i = 0; i < len; ++i)
        res += (wxChar)(*(begin+i));
    
    return res;
}
Exemple #15
0
NS_IMETHODIMP
nsJSON::Decode(const nsAString& json, JSContext* cx, JS::Value* aRetval)
{
  nsresult rv = WarnDeprecatedMethod(DecodeWarning);
  if (NS_FAILED(rv))
    return rv;

  const PRUnichar *data;
  uint32_t len = NS_StringGetData(json, &data);
  nsCOMPtr<nsIInputStream> stream;
  rv = NS_NewByteInputStream(getter_AddRefs(stream),
                             reinterpret_cast<const char*>(data),
                             len * sizeof(PRUnichar),
                             NS_ASSIGNMENT_DEPEND);
  NS_ENSURE_SUCCESS(rv, rv);
  return DecodeInternal(cx, stream, len, false, aRetval);
}
int32_t
nsAString::Compare(const char_type *other, ComparatorFunc c) const
{
  const char_type *cself;
  uint32_t selflen = NS_StringGetData(*this, &cself);
  uint32_t otherlen = NS_strlen(other);
  uint32_t comparelen = selflen <= otherlen ? selflen : otherlen;

  int32_t result = c(cself, other, comparelen);
  if (result == 0) {
    if (selflen < otherlen)
      return -1;
    else if (selflen > otherlen)
      return 1;
  }
  return result;
}
Exemple #17
0
nsDependentSubstring::nsDependentSubstring(const abstract_string_type& aStr,
                                           PRUint32 aStartPos,
                                           PRUint32 aLength)
{
  const PRUnichar* data;
  PRUint32 len = NS_StringGetData(aStr, &data);

  if (aStartPos > len)
    aStartPos = len;

  if (aStartPos + aLength > len)
    aLength = len - aStartPos;

  NS_StringContainerInit2(*this, data + aStartPos, aLength,
                          NS_STRING_CONTAINER_INIT_DEPEND |
                            NS_STRING_CONTAINER_INIT_SUBSTRING);
}
Exemple #18
0
void nsPluginInstance::setProperty(const nsAString &args, PRInt32 *_retval)
{
	// 3 properties can be set
	// {dcsURL:<value>,dmsURL:<value>,screenURL:<value>}


	std::map<std::wstring, std::wstring> argMap;
	argMap.clear();

	const PRUnichar* data = new PRUnichar[args.Length() * sizeof(PRUnichar)];
	NS_StringGetData(args, &data);
	std::wstring localArgs(data);

	BSTR bArgs = ::SysAllocString(localArgs.c_str());

	CTranslator::jsonArgsToMapW(bArgs, argMap);
	std::map<std::wstring, std::wstring>::iterator it;

	for (it = argMap.begin(); it != argMap.end(); it++)
	{
		std::wstring value(it->second);
		if (0 == it->first.compare(L"dcsURL"))
		{
			m_property->setDCSURL(value);
		}
		else if (0 == it->first.compare(L"dmsURL"))
		{
			m_property->setUploadURL(value);
		}
		else if (0 == it->first.compare(L"screenURL"))
		{
			m_property->setScreencastURL(value);
		}
		else
		{
			if (value.compare(L"0") == 0)
				CTranslator::setScreencastProfile(0, "npDimdimControl.dll", "..\\publisher\\");
			else if (value.compare(L"2") == 0)
				CTranslator::setScreencastProfile(2, "npDimdimControl.dll", "..\\publisher\\");
			else
				CTranslator::setScreencastProfile(1, "npDimdimControl.dll", "..\\publisher\\");
		}
	}

	*_retval = 1;
}
Exemple #19
0
void nsPluginInstance::getProperty(const nsAString &args, nsAString &_retval)
{
	// Three property values may be queried
	//
	// 1. windowList - Return JSON buffer of HANDLE-Window Caption pairs
	// 2. screencastResult


	std::map<std::wstring, std::wstring> argMap;
	argMap.clear();

	const PRUnichar* data = new PRUnichar[args.Length() * sizeof(PRUnichar)];
	NS_StringGetData(args, &data);
	std::wstring localArgs(data);

	BSTR bArgs = ::SysAllocString(localArgs.c_str());

	CTranslator::browserArgsToMapW(bArgs, argMap);
	std::map<std::wstring, std::wstring>::iterator it = argMap.find(L"name");

	if (it != argMap.end())
	{
		if (0 == it->second.compare(L"windowList"))
		{
			_retval = m_property->getWindowData();
		}
		else if (0 == it->second.compare(L"screencastResult"))
		{
			_retval = m_property->getScreencastResult();
		}
		else if (0 == it->second.compare(L"BWProfile"))
		{
			_retval = CTranslator::getScreencastProfile();
		}
		else
		{
			_retval = ::SysAllocString(L"");
		}
	}
	else
	{
		_retval = ::SysAllocString(L"");
	}
}
Exemple #20
0
nsDependentSubstring::nsDependentSubstring(const abstract_string_type& aStr,
                                           uint32_t aStartPos,
                                           uint32_t aLength)
{
  const char16_t* data;
  uint32_t len = NS_StringGetData(aStr, &data);

  if (aStartPos > len) {
    aStartPos = len;
  }

  if (aStartPos + aLength > len) {
    aLength = len - aStartPos;
  }

  NS_StringContainerInit2(*this, data + aStartPos, aLength,
                          NS_STRING_CONTAINER_INIT_DEPEND |
                            NS_STRING_CONTAINER_INIT_SUBSTRING);
}
Exemple #21
0
PRUint32 nsAString_GetData(const nsAString *str, const PRUnichar **data, PRBool *termited)
{
    return NS_StringGetData(str, data, termited);
}
static void TestSaveAsCharset()
{
  printf("==============================\n");
  printf("Start nsISaveAsCharset Test \n");
  printf("==============================\n");

  nsresult res;

  nsString inString;
  inString.Assign(NS_ConvertASCIItoUTF16("\x61\x62\x80\xA0\x63"));
  char *outString;
  
  const PRUnichar *data;
  uint32_t length = NS_StringGetData(inString, &data);

  // first, dump input string
  for (uint32_t i = 0; i < length; i++) {
    printf("%c ", data[i]);
  }
  printf("\n");

  nsCOMPtr <nsISaveAsCharset> saveAsCharset = do_CreateInstance(kSaveAsCharsetCID, &res);
  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
  
  printf("ISO-8859-1 attr_plainTextDefault entityNone\n");
  res = saveAsCharset->Init("ISO-8859-1", 
                                 nsISaveAsCharset::attr_plainTextDefault, 
                                 nsIEntityConverter::entityNone);
  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
  res = saveAsCharset->Convert(inString.get(), &outString);
  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
  if (!outString) {printf("\tFailed!! output null\n");}
  else {printf("%s\n", outString); nsMemory::Free(outString);}

  printf("ISO-2022-JP attr_plainTextDefault entityNone\n");
  res = saveAsCharset->Init("ISO-2022-JP", 
                                 nsISaveAsCharset::attr_plainTextDefault,
                                 nsIEntityConverter::entityNone);
  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
  res = saveAsCharset->Convert(inString.get(), &outString);
  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
  if (!outString) {printf("\tFailed!! output null\n");}
  else {printf("%s\n", outString); nsMemory::Free(outString);}
  if (NS_ERROR_UENC_NOMAPPING == res) {
    outString = ToNewUTF8String(inString);
    if (!outString) {printf("\tFailed!! output null\n");}
    else {printf("Fall back to UTF-8: %s\n", outString); nsMemory::Free(outString);}
  }

  printf("ISO-2022-JP attr_FallbackQuestionMark entityNone\n");
  res = saveAsCharset->Init("ISO-2022-JP", 
                                 nsISaveAsCharset::attr_FallbackQuestionMark,
                                 nsIEntityConverter::entityNone);
  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
  res = saveAsCharset->Convert(inString.get(), &outString);
  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
  if (!outString) {printf("\tFailed!! output null\n");}
  else {printf("%s\n", outString); nsMemory::Free(outString);}

  printf("ISO-2022-JP attr_FallbackEscapeU entityNone\n");
  res = saveAsCharset->Init("ISO-2022-JP", 
                                 nsISaveAsCharset::attr_FallbackEscapeU,
                                 nsIEntityConverter::entityNone);
  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
  res = saveAsCharset->Convert(inString.get(), &outString);
  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
  if (!outString) {printf("\tFailed!! output null\n");}
  else {printf("%s\n", outString); nsMemory::Free(outString);}

  printf("ISO-8859-1 attr_htmlTextDefault html40Latin1\n");
  res = saveAsCharset->Init("ISO-8859-1", 
                                 nsISaveAsCharset::attr_htmlTextDefault, 
                                 nsIEntityConverter::html40Latin1);
  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
  res = saveAsCharset->Convert(inString.get(), &outString);
  if (NS_ERROR_UENC_NOMAPPING != res && NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
  if (!outString) {printf("\tFailed!! output null\n");}
  else {printf("%s\n", outString); nsMemory::Free(outString);}

  printf("ISO-8859-1 attr_FallbackHexNCR+attr_EntityAfterCharsetConv html40Latin1 \n");
  res = saveAsCharset->Init("ISO-8859-1", 
                                 nsISaveAsCharset::attr_FallbackHexNCR + 
                                 nsISaveAsCharset::attr_EntityAfterCharsetConv, 
                                 nsIEntityConverter::html40Latin1);
  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
  res = saveAsCharset->Convert(inString.get(), &outString);
  if (NS_ERROR_UENC_NOMAPPING != res && NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
  if (!outString) {printf("\tFailed!! output null\n");}
  else {printf("%s\n", outString); nsMemory::Free(outString);}


  printf("==============================\n");
  printf("Finish nsISaveAsCharset Test \n");
  printf("==============================\n\n");
}
Exemple #23
0
void nsPluginInstance::performAction(const nsAString &args, PRInt32 *_retval)
{
	std::map<std::wstring, std::wstring> argMap;
	argMap.clear();

	const PRUnichar* data = new PRUnichar[args.Length() * sizeof(PRUnichar)];
	NS_StringGetData(args, &data); 
	std::wstring localArgs(data);

	BSTR bArgs = ::SysAllocString(localArgs.c_str());

	CTranslator::browserArgsToMapW(bArgs, argMap);
	std::map<std::wstring, std::wstring>::iterator it = argMap.find(L"operation");
	std::map<std::wstring, std::wstring>::iterator regit = argMap.find(L"reg");

	if (it != argMap.end())
	{
		if (0 == it->second.compare(L"screencast"))
		{
			if (1 == m_property->remoteDesktop())
			{
				*_retval = 1;
				return;
			}
			CTranslator::executePublisherRunW();

			if (regit != argMap.end())
			{
				m_property->setRegistration(regit->second);
				if (false == CPublisherIO::getInstance()->validateRegistration(m_property))
				{
					*_retval = -1;
					return;
				}
			}
			else
			{
				*_retval = -1;
				return;
			}

			it = argMap.find(L"action");
			if (it != argMap.end())
			{
				if (0 == it->second.compare(L"share"))
				{
					CTranslator::executeScreencasterRunW();
					CTranslator::executeScreencasterRunTrackW();
					setupDriver();
					//if (1 != m_property->driverInstalled())
					//	CTranslator::invokeDriverInstall();

					it = argMap.find(L"handle");
					if (it != argMap.end())
					{
						LONG handle = StrToIntW(it->second.c_str());
						if (false == m_property->isValidHandle(handle))
						{
							m_property->setScreencastResult(L"{screencastResult:\"4\"}");
							*_retval = 1;
							return;
						}

						if (0 != wcscmp(m_property->getScreencastResult(false), L"{screencastResult:\"1\"}"))
						{
							m_property->setScreencastResult(L"{screencastResult:\"0\"}");
							CTranslator::executeScreencasterShareAndConnectW(it->second, m_property->getScreencastURL());
						}
						else
						{
							CTranslator::executeScreencasterShareW(it->second);
						}

						*_retval = 1;
						return;
					}
				}
				else
				{
					CTranslator::executeScreencasterStopW();
					*_retval = 1;
					return;
				}
			}
		}
		else if (0 == it->second.compare(L"mint"))
		{
			it = argMap.find(L"action");
			if (it != argMap.end())
			{
				if (0 == it->second.compare(L"run"))
				{
					CTranslator::executePublisherRunW();
				}
				else if (0 == it->second.compare(L"installDriver"))
				{
					CTranslator::invokeDriverInstall();
				}
				else if (0 == it->second.compare(L"checkDriver"))
				{
					//*_retval = m_property->driverInstalled();
					*_retval = 1;
					return;
				}
				else
				{
					CTranslator::executePublisherKillW();
				}
			}
			*_retval = 1;
		}
	}

	*_retval = 0;
}
Exemple #24
0
gluezilla_StringGetData (const nsAString &aStr, const PRUnichar **aBuf, PRBool *aTerm)
{
	return NS_StringGetData (aStr, aBuf, aTerm);
}