本文整理汇总了C++中nsACString::EndReading方法的典型用法代码示例。如果您正苦于以下问题:C++ nsACString::EndReading方法的具体用法?C++ nsACString::EndReading怎么用?C++ nsACString::EndReading使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsACString
的用法示例。
在下文中一共展示了nsACString::EndReading方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: converter
bool
AppendUTF8toUTF16( const nsACString& aSource, nsAString& aDest,
const mozilla::fallible_t& )
{
nsACString::const_iterator source_start, source_end;
CalculateUTF8Length calculator;
copy_string(aSource.BeginReading(source_start),
aSource.EndReading(source_end), calculator);
uint32_t count = calculator.Length();
// Avoid making the string mutable if we're appending an empty string
if (count)
{
uint32_t old_dest_length = aDest.Length();
// Grow the buffer if we need to.
if (!aDest.SetLength(old_dest_length + count, mozilla::fallible_t())) {
return false;
}
// All ready? Time to convert
ConvertUTF8toUTF16 converter(aDest.BeginWriting() + old_dest_length);
copy_string(aSource.BeginReading(source_start),
aSource.EndReading(source_end), converter);
NS_ASSERTION(converter.ErrorEncountered() ||
converter.Length() == count,
"CalculateUTF8Length produced the wrong length");
if (converter.ErrorEncountered())
{
NS_ERROR("Input wasn't UTF8 or incorrect length was calculated");
aDest.SetLength(old_dest_length);
}
}
return true;
}
示例2: iter
void
URLParams::ParseInput(const nsACString& aInput)
{
// Remove all the existing data before parsing a new input.
DeleteAll();
nsACString::const_iterator start, end;
aInput.BeginReading(start);
aInput.EndReading(end);
nsACString::const_iterator iter(start);
while (start != end) {
nsAutoCString string;
if (FindCharInReadable('&', iter, end)) {
string.Assign(Substring(start, iter));
start = ++iter;
} else {
string.Assign(Substring(start, end));
start = end;
}
if (string.IsEmpty()) {
continue;
}
nsACString::const_iterator eqStart, eqEnd;
string.BeginReading(eqStart);
string.EndReading(eqEnd);
nsACString::const_iterator eqIter(eqStart);
nsAutoCString name;
nsAutoCString value;
if (FindCharInReadable('=', eqIter, eqEnd)) {
name.Assign(Substring(eqStart, eqIter));
++eqIter;
value.Assign(Substring(eqIter, eqEnd));
} else {
name.Assign(string);
}
nsAutoString decodedName;
DecodeString(name, decodedName);
nsAutoString decodedValue;
DecodeString(value, decodedValue);
Append(decodedName, decodedValue);
}
}
示例3: first
void
URLSearchParams::DecodeString(const nsACString& aInput, nsACString& aOutput)
{
nsACString::const_iterator start, end;
aInput.BeginReading(start);
aInput.EndReading(end);
while (start != end) {
// replace '+' with U+0020
if (*start == '+') {
aOutput.Append(' ');
++start;
continue;
}
// Percent decode algorithm
if (*start == '%') {
nsACString::const_iterator first(start);
++first;
nsACString::const_iterator second(first);
++second;
#define ASCII_HEX_DIGIT( x ) \
((x >= 0x41 && x <= 0x46) || \
(x >= 0x61 && x <= 0x66) || \
(x >= 0x30 && x <= 0x39))
#define HEX_DIGIT( x ) \
(*x >= 0x30 && *x <= 0x39 \
? *x - 0x30 \
: (*x >= 0x41 && *x <= 0x46 \
? *x - 0x37 \
: *x - 0x57))
if (first != end && second != end &&
ASCII_HEX_DIGIT(*first) && ASCII_HEX_DIGIT(*second)) {
aOutput.Append(HEX_DIGIT(first) * 16 + HEX_DIGIT(second));
start = ++second;
continue;
} else {
aOutput.Append('%');
++start;
continue;
}
}
aOutput.Append(*start);
++start;
}
}
示例4: ReverseString
void ReverseString(const nsACString& aSource, nsACString& aResult) {
nsACString::const_iterator sourceBegin, sourceEnd;
aSource.BeginReading(sourceBegin);
aSource.EndReading(sourceEnd);
aResult.SetLength(aSource.Length());
auto destEnd = aResult.EndWriting();
while (sourceBegin != sourceEnd) {
*(--destEnd) = *sourceBegin;
++sourceBegin;
}
}
示例5: nodeBegin
NS_IMETHODIMP
nsLocalFile::SetRelativeDescriptor(nsIFile* aFromFile,
const nsACString& aRelativeDesc)
{
NS_NAMED_LITERAL_CSTRING(kParentDirStr, "../");
nsCOMPtr<nsIFile> targetFile;
nsresult rv = aFromFile->Clone(getter_AddRefs(targetFile));
if (NS_FAILED(rv)) {
return rv;
}
//
// aRelativeDesc is UTF-8 encoded
//
nsCString::const_iterator strBegin, strEnd;
aRelativeDesc.BeginReading(strBegin);
aRelativeDesc.EndReading(strEnd);
nsCString::const_iterator nodeBegin(strBegin), nodeEnd(strEnd);
nsCString::const_iterator pos(strBegin);
nsCOMPtr<nsIFile> parentDir;
while (FindInReadable(kParentDirStr, nodeBegin, nodeEnd)) {
rv = targetFile->GetParent(getter_AddRefs(parentDir));
if (NS_FAILED(rv)) {
return rv;
}
if (!parentDir) {
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
}
targetFile = parentDir;
nodeBegin = nodeEnd;
pos = nodeEnd;
nodeEnd = strEnd;
}
nodeBegin = nodeEnd = pos;
while (nodeEnd != strEnd) {
FindCharInReadable('/', nodeEnd, strEnd);
targetFile->Append(NS_ConvertUTF8toUTF16(Substring(nodeBegin, nodeEnd)));
if (nodeEnd != strEnd) { // If there's more left in the string, inc over the '/' nodeEnd is on.
++nodeEnd;
}
nodeBegin = nodeEnd;
}
return InitWithFile(targetFile);
}
示例6:
// copy aSource strings into contiguous storage provided in aDest1,
// providing terminating nulls for each destination string.
static inline void
StrBlockCopy(const nsACString &aSource1,
const nsACString &aSource2,
const nsACString &aSource3,
const nsACString &aSource4,
char *&aDest1,
char *&aDest2,
char *&aDest3,
char *&aDest4,
char *&aDestEnd)
{
char *toBegin = aDest1;
nsACString::const_iterator fromBegin, fromEnd;
*copy_string(aSource1.BeginReading(fromBegin), aSource1.EndReading(fromEnd), toBegin) = char(0);
aDest2 = ++toBegin;
*copy_string(aSource2.BeginReading(fromBegin), aSource2.EndReading(fromEnd), toBegin) = char(0);
aDest3 = ++toBegin;
*copy_string(aSource3.BeginReading(fromBegin), aSource3.EndReading(fromEnd), toBegin) = char(0);
aDest4 = ++toBegin;
*copy_string(aSource4.BeginReading(fromBegin), aSource4.EndReading(fromEnd), toBegin) = char(0);
aDestEnd = toBegin;
}
示例7: origLabel
nsresult nsIDNService::ACEtoUTF8(const nsACString & input, nsACString & _retval,
stringPrepFlag flag)
{
// RFC 3490 - 4.2 ToUnicode
// ToUnicode never fails. If any step fails, then the original input
// sequence is returned immediately in that step.
//
// Note that this refers to the decoding of a single label.
// ACEtoUTF8 may be called with a sequence of labels separated by dots;
// this test applies individually to each label.
uint32_t len = 0, offset = 0;
nsAutoCString decodedBuf;
nsACString::const_iterator start, end;
input.BeginReading(start);
input.EndReading(end);
_retval.Truncate();
// loop and decode nodes
while (start != end) {
len++;
if (*start++ == '.') {
nsDependentCSubstring origLabel(input, offset, len - 1);
if (NS_FAILED(decodeACE(origLabel, decodedBuf, flag))) {
// If decoding failed, use the original input sequence
// for this label.
_retval.Append(origLabel);
} else {
_retval.Append(decodedBuf);
}
_retval.Append('.');
offset += len;
len = 0;
}
}
// decode the last node
if (len) {
nsDependentCSubstring origLabel(input, offset, len);
if (NS_FAILED(decodeACE(origLabel, decodedBuf, flag))) {
_retval.Append(origLabel);
} else {
_retval.Append(decodedBuf);
}
}
return NS_OK;
}
示例8: SubstitutingURL
nsresult
SubstitutingProtocolHandler::NewURI(const nsACString &aSpec,
const char *aCharset,
nsIURI *aBaseURI,
nsIURI **result)
{
nsresult rv;
RefPtr<SubstitutingURL> url = new SubstitutingURL();
if (!url)
return NS_ERROR_OUT_OF_MEMORY;
// unescape any %2f and %2e to make sure nsStandardURL coalesces them.
// Later net_GetFileFromURLSpec() will do a full unescape and we want to
// treat them the same way the file system will. (bugs 380994, 394075)
nsAutoCString spec;
const char *src = aSpec.BeginReading();
const char *end = aSpec.EndReading();
const char *last = src;
spec.SetCapacity(aSpec.Length()+1);
for ( ; src < end; ++src) {
if (*src == '%' && (src < end-2) && *(src+1) == '2') {
char ch = '\0';
if (*(src+2) == 'f' || *(src+2) == 'F') {
ch = '/';
} else if (*(src+2) == 'e' || *(src+2) == 'E') {
ch = '.';
}
if (ch) {
if (last < src) {
spec.Append(last, src-last);
}
spec.Append(ch);
src += 2;
last = src+1; // src will be incremented by the loop
}
}
}
if (last < src)
spec.Append(last, src-last);
rv = url->Init(nsIStandardURL::URLTYPE_STANDARD, -1, spec, aCharset, aBaseURI);
if (NS_SUCCEEDED(rv)) {
url.forget(result);
}
return rv;
}
示例9: if
NS_IMETHODIMP
nsResProtocolHandler::NewURI(const nsACString &aSpec,
const char *aCharset,
nsIURI *aBaseURI,
nsIURI **result)
{
nsresult rv;
nsResURL *resURL = new nsResURL();
if (!resURL)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(resURL);
// unescape any %2f and %2e to make sure nsStandardURL coalesces them.
// Later net_GetFileFromURLSpec() will do a full unescape and we want to
// treat them the same way the file system will. (bugs 380994, 394075)
nsCAutoString spec;
const char *src = aSpec.BeginReading();
const char *end = aSpec.EndReading();
const char *last = src;
spec.SetCapacity(aSpec.Length()+1);
for ( ; src < end; ++src) {
if (*src == '%' && (src < end-2) && *(src+1) == '2') {
char ch = '\0';
if (*(src+2) == 'f' || *(src+2) == 'F')
ch = '/';
else if (*(src+2) == 'e' || *(src+2) == 'E')
ch = '.';
if (ch) {
if (last < src)
spec.Append(last, src-last);
spec.Append(ch);
src += 2;
last = src+1; // src will be incremented by the loop
}
}
}
if (last < src)
spec.Append(last, src-last);
rv = resURL->Init(nsIStandardURL::URLTYPE_STANDARD, -1, spec, aCharset, aBaseURI);
if (NS_SUCCEEDED(rv))
rv = CallQueryInterface(resURL, result);
NS_RELEASE(resURL);
return rv;
}
示例10:
// static
bool
nsHttp::IsReasonableHeaderValue(const nsACString &s)
{
// Header values MUST NOT contain line-breaks. RFC 2616 technically
// permits CTL characters, including CR and LF, in header values provided
// they are quoted. However, this can lead to problems if servers do not
// interpret quoted strings properly. Disallowing CR and LF here seems
// reasonable and keeps things simple. We also disallow a null byte.
const nsACString::char_type* end = s.EndReading();
for (const nsACString::char_type* i = s.BeginReading(); i != end; ++i) {
if (*i == '\r' || *i == '\n' || *i == '\0') {
return false;
}
}
return true;
}
示例11: pathBeginsWithVolName
static bool pathBeginsWithVolName(const nsACString& path, nsACString& firstPathComponent)
{
// Return whether the 1st path component in path (escaped) is equal to the name
// of a mounted volume. Return the 1st path component (unescaped) in any case.
// This needs to be done as quickly as possible, so we cache a list of volume names.
// XXX Register an event handler to detect drives being mounted/unmounted?
if (!gVolumeList) {
gVolumeList = new nsTArray<nsCString>;
if (!gVolumeList) {
return false; // out of memory
}
}
// Cache a list of volume names
if (!gVolumeList->Length()) {
OSErr err;
ItemCount volumeIndex = 1;
do {
HFSUniStr255 volName;
FSRef rootDirectory;
err = ::FSGetVolumeInfo(0, volumeIndex, NULL, kFSVolInfoNone, NULL, &volName, &rootDirectory);
if (err == noErr) {
NS_ConvertUTF16toUTF8 volNameStr(Substring((PRUnichar *)volName.unicode,
(PRUnichar *)volName.unicode + volName.length));
gVolumeList->AppendElement(volNameStr);
volumeIndex++;
}
} while (err == noErr);
}
// Extract the first component of the path
nsACString::const_iterator start;
path.BeginReading(start);
start.advance(1); // path begins with '/'
nsACString::const_iterator directory_end;
path.EndReading(directory_end);
nsACString::const_iterator component_end(start);
FindCharInReadable('/', component_end, directory_end);
nsCAutoString flatComponent((Substring(start, component_end)));
NS_UnescapeURL(flatComponent);
PRInt32 foundIndex = gVolumeList->IndexOf(flatComponent);
firstPathComponent = flatComponent;
return (foundIndex != -1);
}
示例12: while
nsresult nsIDNService::ACEtoUTF8(const nsACString & input, nsACString & _retval,
bool allowUnassigned)
{
// RFC 3490 - 4.2 ToUnicode
// ToUnicode never fails. If any step fails, then the original input
// sequence is returned immediately in that step.
if (!IsASCII(input)) {
_retval.Assign(input);
return NS_OK;
}
uint32_t len = 0, offset = 0;
nsAutoCString decodedBuf;
nsACString::const_iterator start, end;
input.BeginReading(start);
input.EndReading(end);
_retval.Truncate();
// loop and decode nodes
while (start != end) {
len++;
if (*start++ == '.') {
if (NS_FAILED(decodeACE(Substring(input, offset, len - 1), decodedBuf,
allowUnassigned))) {
_retval.Assign(input);
return NS_OK;
}
_retval.Append(decodedBuf);
_retval.Append('.');
offset += len;
len = 0;
}
}
// decode the last node
if (len) {
if (NS_FAILED(decodeACE(Substring(input, offset, len), decodedBuf,
allowUnassigned)))
_retval.Assign(input);
else
_retval.Append(decodedBuf);
}
return NS_OK;
}
示例13: while
static void
SplitTables(const nsACString& str, nsTArray<nsCString>& tables)
{
tables.Clear();
nsACString::const_iterator begin, iter, end;
str.BeginReading(begin);
str.EndReading(end);
while (begin != end) {
iter = begin;
FindCharInReadable(',', iter, end);
tables.AppendElement(Substring(begin, iter));
begin = iter;
if (begin != end)
begin++;
}
}
示例14:
bool
nsPicoService::GetVoiceFileLanguage(const nsACString& aFileName, nsAString& aLang)
{
nsACString::const_iterator start, end;
aFileName.BeginReading(start);
aFileName.EndReading(end);
// The lingware filename syntax is language_(ta/sg).bin,
// we extract the language prefix here.
if (FindInReadable(NS_LITERAL_CSTRING("_"), start, end)) {
end = start;
aFileName.BeginReading(start);
aLang.Assign(NS_ConvertUTF8toUTF16(Substring(start, end)));
return true;
}
return false;
}
示例15: while
uint32_t
CountCharInReadable(const nsACString& aStr, char aChar)
{
uint32_t count = 0;
nsACString::const_iterator begin, end;
aStr.BeginReading(begin);
aStr.EndReading(end);
while (begin != end) {
if (*begin == aChar) {
++count;
}
++begin;
}
return count;
}