本文整理汇总了C++中nsCString::BeginReading方法的典型用法代码示例。如果您正苦于以下问题:C++ nsCString::BeginReading方法的具体用法?C++ nsCString::BeginReading怎么用?C++ nsCString::BeginReading使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsCString
的用法示例。
在下文中一共展示了nsCString::BeginReading方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
static void
rdf_EscapeAmpersandsAndAngleBrackets(nsCString& s)
{
uint32_t newLength, origLength;
newLength = origLength = s.Length();
// Compute the length of the result string.
const char* start = s.BeginReading();
const char* end = s.EndReading();
const char* c = start;
while (c != end) {
switch (*c) {
case '&' :
newLength += sizeof(amp) - 2;
break;
case '<':
case '>':
newLength += sizeof(gt) - 2;
break;
default:
break;
}
++c;
}
if (newLength == origLength) {
// nothing to escape
return;
}
// escape the chars from the end back to the front.
s.SetLength(newLength);
// Buffer might have changed, get the pointers again
start = s.BeginReading(); // begin of string
c = start + origLength - 1; // last char in original string
char* w = s.EndWriting() - 1; // last char in grown buffer
while (c >= start) {
switch (*c) {
case '&' :
w -= 4;
nsCharTraits<char>::copy(w, amp, sizeof(amp) - 1);
break;
case '<':
w -= 3;
nsCharTraits<char>::copy(w, lt, sizeof(lt) - 1);
break;
case '>':
w -= 3;
nsCharTraits<char>::copy(w, gt, sizeof(gt) - 1);
break;
default:
*w = *c;
}
--w;
--c;
}
}
示例2: GetCacheKey
nsresult nsDOMOfflineResourceList::GetCacheKey(nsIURI* aURI, nsCString& aKey) {
nsresult rv = aURI->GetAsciiSpec(aKey);
NS_ENSURE_SUCCESS(rv, rv);
// url fragments aren't used in cache keys
nsAutoCString::const_iterator specStart, specEnd;
aKey.BeginReading(specStart);
aKey.EndReading(specEnd);
if (FindCharInReadable('#', specStart, specEnd)) {
aKey.BeginReading(specEnd);
aKey = Substring(specEnd, specStart);
}
return NS_OK;
}
示例3: nsMsgI18NConvertRawBytesToUTF16
void nsMsgI18NConvertRawBytesToUTF16(const nsCString& inString,
const char* charset,
nsAString& outString)
{
if (MsgIsUTF8(inString))
{
CopyUTF8toUTF16(inString, outString);
return;
}
nsresult rv = ConvertToUnicode(charset, inString, outString);
if (NS_SUCCEEDED(rv))
return;
const char* cur = inString.BeginReading();
const char* end = inString.EndReading();
outString.Truncate();
while (cur < end) {
char c = *cur++;
if (c & char(0x80))
outString.Append(UCS2_REPLACEMENT_CHAR);
else
outString.Append(c);
}
}
示例4: ConnectInternal
nsresult UDPSocketParent::ConnectInternal(const nsCString& aHost,
const uint16_t& aPort) {
nsresult rv;
UDPSOCKET_LOG(("%s: %s:%u", __FUNCTION__, nsCString(aHost).get(), aPort));
if (!mSocket) {
return NS_ERROR_NOT_AVAILABLE;
}
PRNetAddr prAddr;
memset(&prAddr, 0, sizeof(prAddr));
PR_InitializeNetAddr(PR_IpAddrAny, aPort, &prAddr);
PRStatus status = PR_StringToNetAddr(aHost.BeginReading(), &prAddr);
if (status != PR_SUCCESS) {
return NS_ERROR_FAILURE;
}
mozilla::net::NetAddr addr;
PRNetAddrToNetAddr(&prAddr, &addr);
rv = mSocket->Connect(&addr);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
示例5: IsLikelyFTP
/**
* Check if the host name starts with ftp\d*\. and it's not directly followed
* by the tld.
*/
bool nsDefaultURIFixup::IsLikelyFTP(const nsCString &aHostSpec)
{
bool likelyFTP = false;
if (aHostSpec.EqualsIgnoreCase("ftp", 3)) {
nsACString::const_iterator iter;
nsACString::const_iterator end;
aHostSpec.BeginReading(iter);
aHostSpec.EndReading(end);
iter.advance(3); // move past the "ftp" part
while (iter != end)
{
if (*iter == '.') {
// now make sure the name has at least one more dot in it
++iter;
while (iter != end)
{
if (*iter == '.') {
likelyFTP = true;
break;
}
++iter;
}
break;
}
else if (!nsCRT::IsAsciiDigit(*iter)) {
break;
}
++iter;
}
}
return likelyFTP;
}
示例6: nsMsgI18NConvertRawBytesToUTF8
void nsMsgI18NConvertRawBytesToUTF8(const nsCString& inString,
const char* charset,
nsACString& outString)
{
if (MsgIsUTF8(inString))
{
outString.Assign(inString);
return;
}
nsAutoString utf16Text;
nsresult rv = ConvertToUnicode(charset, inString, utf16Text);
if (NS_SUCCEEDED(rv))
{
CopyUTF16toUTF8(utf16Text, outString);
return;
}
// EF BF BD (UTF-8 encoding of U+FFFD)
NS_NAMED_LITERAL_CSTRING(utf8ReplacementChar, "\357\277\275");
const char* cur = inString.BeginReading();
const char* end = inString.EndReading();
outString.Truncate();
while (cur < end) {
char c = *cur++;
if (c & char(0x80))
outString.Append(utf8ReplacementChar);
else
outString.Append(c);
}
}
示例7: memcpy
static void
MorkUnescape(const nsCSubstring &aString, nsCString &aResult)
{
PRUint32 len = aString.Length();
// We optimize for speed over space here -- size the result buffer to
// the size of the source, which is an upper bound on the size of the
// unescaped string.
// FIXME: Mork assume there will never be errors
if (!EnsureStringLength(aResult, len)) {
aResult.Truncate();
return; // out of memory.
}
char *result = aResult.BeginWriting();
const char *source = aString.BeginReading();
const char *sourceEnd = source + len;
const char *startPos = nsnull;
PRUint32 bytes;
for (; source < sourceEnd; ++source) {
char c = *source;
if (c == '\\') {
if (startPos) {
bytes = source - startPos;
memcpy(result, startPos, bytes);
result += bytes;
startPos = nsnull;
}
if (source < sourceEnd - 1) {
*(result++) = *(++source);
}
} else if (c == '$') {
if (startPos) {
bytes = source - startPos;
memcpy(result, startPos, bytes);
result += bytes;
startPos = nsnull;
}
if (source < sourceEnd - 2) {
// Would be nice to use ToInteger() here, but it currently
// requires a null-terminated string.
char c2 = *(++source);
char c3 = *(++source);
if (ConvertChar(&c2) && ConvertChar(&c3)) {
*(result++) = ((c2 << 4) | c3);
}
}
} else if (!startPos) {
startPos = source;
}
}
if (startPos) {
bytes = source - startPos;
memcpy(result, startPos, bytes);
result += bytes;
}
aResult.SetLength(result - aResult.BeginReading());
}
示例8: ReplaceChar
static void ReplaceChar(nsCString& str, const nsACString& character,
const nsACString& replacement)
{
nsCString::const_iterator start, end;
str.BeginReading(start);
str.EndReading(end);
while (FindInReadable(character, start, end)) {
PRInt32 pos = end.size_backward();
str.Replace(pos - 1, 1, replacement);
str.BeginReading(start);
start.advance(pos + replacement.Length() - 1);
str.EndReading(end);
}
}
示例9: Substring
nsMediaFragmentURIParser::nsMediaFragmentURIParser(const nsCString& aSpec)
{
nsReadingIterator<char> start, end;
aSpec.BeginReading(start);
aSpec.EndReading(end);
if (FindCharInReadable('#', start, end)) {
mHash = Substring(++start, end);
}
}
示例10:
bool
GMPChild::RecvSetNodeId(const nsCString& aNodeId)
{
// Store the per origin salt for the node id. Note: we do this in a
// separate message than RecvStartPlugin() so that the string is not
// sitting in a string on the IPC code's call stack.
mNodeId = std::string(aNodeId.BeginReading(), aNodeId.EndReading());
return true;
}
示例11: FireInternalError
bool
UDPSocketParent::Init(const nsCString &aHost, const uint16_t aPort)
{
nsresult rv;
NS_ASSERTION(mFilter, "No packet filter");
nsCOMPtr<nsIUDPSocket> sock =
do_CreateInstance("@mozilla.org/network/udp-socket;1", &rv);
if (NS_FAILED(rv)) {
FireInternalError(this, __LINE__);
return true;
}
if (aHost.IsEmpty()) {
rv = sock->Init(aPort, false);
} else {
PRNetAddr prAddr;
PR_InitializeNetAddr(PR_IpAddrAny, aPort, &prAddr);
PRStatus status = PR_StringToNetAddr(aHost.BeginReading(), &prAddr);
if (status != PR_SUCCESS) {
FireInternalError(this, __LINE__);
return true;
}
mozilla::net::NetAddr addr;
PRNetAddrToNetAddr(&prAddr, &addr);
rv = sock->InitWithAddress(&addr);
}
if (NS_FAILED(rv)) {
FireInternalError(this, __LINE__);
return true;
}
mSocket = sock;
net::NetAddr localAddr;
mSocket->GetAddress(&localAddr);
uint16_t port;
nsCString addr;
rv = ConvertNetAddrToString(localAddr, &addr, &port);
if (NS_FAILED(rv)) {
FireInternalError(this, __LINE__);
return true;
}
// register listener
mSocket->AsyncListen(this);
mozilla::unused <<
PUDPSocketParent::SendCallback(NS_LITERAL_CSTRING("onopen"),
UDPAddressInfo(addr, port),
NS_LITERAL_CSTRING("connected"));
return true;
}
示例12: userNameStr
void
WebGLShader::BindAttribLocation(GLuint prog, const nsCString& userName,
GLuint index) const
{
std::string userNameStr(userName.BeginReading());
const std::string* mappedNameStr = &userNameStr;
if (mValidator)
mValidator->FindAttribMappedNameByUserName(userNameStr, &mappedNameStr);
mContext->gl->fBindAttribLocation(prog, index, mappedNameStr->c_str());
}
示例13: nsCString
nsresult
UDPSocketParent::BindInternal(const nsCString& aHost, const uint16_t& aPort,
const bool& aAddressReuse, const bool& aLoopback)
{
nsresult rv;
UDPSOCKET_LOG(("%s: %s:%u", __FUNCTION__, nsCString(aHost).get(), aPort));
nsCOMPtr<nsIUDPSocket> sock =
do_CreateInstance("@mozilla.org/network/udp-socket;1", &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (aHost.IsEmpty()) {
rv = sock->Init(aPort, false, mPrincipal, aAddressReuse,
/* optional_argc = */ 1);
} else {
PRNetAddr prAddr;
PR_InitializeNetAddr(PR_IpAddrAny, aPort, &prAddr);
PRStatus status = PR_StringToNetAddr(aHost.BeginReading(), &prAddr);
if (status != PR_SUCCESS) {
return NS_ERROR_FAILURE;
}
mozilla::net::NetAddr addr;
PRNetAddrToNetAddr(&prAddr, &addr);
rv = sock->InitWithAddress(&addr, mPrincipal, aAddressReuse,
/* optional_argc = */ 1);
}
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = sock->SetMulticastLoopback(aLoopback);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// register listener
rv = sock->AsyncListen(this);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mSocket = sock;
return NS_OK;
}
示例14:
bool
NeckoParent::RecvRemoveRequestContext(const nsCString& rcid)
{
nsCOMPtr<nsIRequestContextService> rcsvc =
do_GetService("@mozilla.org/network/request-context-service;1");
if (!rcsvc) {
return true;
}
nsID id;
id.Parse(rcid.BeginReading());
rcsvc->RemoveRequestContext(id);
return true;
}
示例15:
bool
NeckoParent::RecvRemoveSchedulingContext(const nsCString& scid)
{
nsCOMPtr<nsISchedulingContextService> scsvc =
do_GetService("@mozilla.org/network/scheduling-context-service;1");
if (!scsvc) {
return true;
}
nsID id;
id.Parse(scid.BeginReading());
scsvc->RemoveSchedulingContext(id);
return true;
}