本文整理汇总了C++中nsAString::BeginReading方法的典型用法代码示例。如果您正苦于以下问题:C++ nsAString::BeginReading方法的具体用法?C++ nsAString::BeginReading怎么用?C++ nsAString::BeginReading使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsAString
的用法示例。
在下文中一共展示了nsAString::BeginReading方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: iter
void
URLMainThread::SetProtocol(const nsAString& aProtocol, ErrorResult& aRv)
{
nsAString::const_iterator start, end;
aProtocol.BeginReading(start);
aProtocol.EndReading(end);
nsAString::const_iterator iter(start);
FindCharInReadable(':', iter, end);
// Changing the protocol of a URL, changes the "nature" of the URI
// implementation. In order to do this properly, we have to serialize the
// existing URL and reparse it in a new object.
nsCOMPtr<nsIURI> clone;
nsresult rv = NS_MutateURI(GetURI())
.SetScheme(NS_ConvertUTF16toUTF8(Substring(start, iter)))
.Finalize(clone);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
nsAutoCString href;
rv = clone->GetSpec(href);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
nsCOMPtr<nsIURI> uri;
rv = NS_NewURI(getter_AddRefs(uri), href);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
SetURI(uri.forget());
}
示例2: while
static void utf16ToUcs4(const nsAString& in, uint32_t *out, uint32_t outBufLen, uint32_t *outLen)
{
uint32_t i = 0;
nsAString::const_iterator start, end;
in.BeginReading(start);
in.EndReading(end);
while (start != end) {
PRUnichar curChar;
curChar= *start++;
if (start != end &&
NS_IS_HIGH_SURROGATE(curChar) &&
NS_IS_LOW_SURROGATE(*start)) {
out[i] = SURROGATE_TO_UCS4(curChar, *start);
++start;
}
else
out[i] = curChar;
i++;
if (i >= outBufLen) {
NS_ERROR("input too big, the result truncated");
out[outBufLen-1] = (uint32_t)'\0';
*outLen = outBufLen-1;
return;
}
}
out[i] = (uint32_t)'\0';
*outLen = i;
}
示例3:
void
nsCSSScanner::Init(const nsAString& aBuffer,
nsIURI* aURI, uint32_t aLineNumber,
nsCSSStyleSheet* aSheet, mozilla::css::Loader* aLoader)
{
NS_PRECONDITION(!mReadPointer, "Should not have an existing input buffer!");
mReadPointer = aBuffer.BeginReading();
mCount = aBuffer.Length();
#ifdef CSS_REPORT_PARSE_ERRORS
// If aURI is different from mCachedURI, invalidate the filename cache.
if (aURI != mCachedURI) {
mCachedURI = aURI;
mCachedFileName.Truncate();
}
#endif // CSS_REPORT_PARSE_ERRORS
mLineNumber = aLineNumber;
// Reset variables that we use to keep track of our progress through the input
mOffset = 0;
mPushbackCount = 0;
mRecording = false;
#ifdef CSS_REPORT_PARSE_ERRORS
mColNumber = 0;
mSheet = aSheet;
mLoader = aLoader;
#endif
}
示例4:
nsresult
NS_CopyUnicodeToNative(const nsAString &input, nsACString &output)
{
PRUint32 inputLen = input.Length();
nsAString::const_iterator iter;
input.BeginReading(iter);
const PRUnichar *buf = iter.get();
// determine length of result
PRUint32 resultLen = 0;
int n = ::WideCharToMultiByte(CP_ACP, 0, buf, inputLen, NULL, 0, NULL, NULL);
if (n > 0)
resultLen += n;
// allocate sufficient space
if (!EnsureStringLength(output, resultLen))
return NS_ERROR_OUT_OF_MEMORY;
if (resultLen > 0) {
nsACString::iterator out_iter;
output.BeginWriting(out_iter);
// default "defaultChar" is '?', which is an illegal character on windows
// file system. That will cause file uncreatable. Change it to '_'
const char defaultChar = '_';
char *result = out_iter.get();
::WideCharToMultiByte(CP_ACP, 0, buf, inputLen, result, resultLen,
&defaultChar, NULL);
}
return NS_OK;
}
示例5: resetCurValue
void
nsCSPParser::resetCurChar(const nsAString& aToken)
{
mCurChar = aToken.BeginReading();
mEndChar = aToken.EndReading();
resetCurValue();
}
示例6: encodeToRACE
static nsresult encodeToRACE(const char* prefix, const nsAString& in, nsACString& out)
{
// need maximum 20 bits to encode 16 bit Unicode character
// (include null terminator)
const uint32_t kEncodedBufSize = kMaxDNSNodeLen * 20 / 8 + 1 + 1;
// set up a work buffer for RACE encoder
PRUnichar temp[kMaxDNSNodeLen + 2];
temp[0] = 0xFFFF; // set a place holder (to be filled by get_compress_mode)
temp[in.Length() + 1] = (PRUnichar)'\0';
nsAString::const_iterator start, end;
in.BeginReading(start);
in.EndReading(end);
for (uint32_t i = 1; start != end; i++)
temp[i] = *start++;
// encode nodes if non ASCII
char encodedBuf[kEncodedBufSize];
idn_result_t result = race_compress_encode((const unsigned short *) temp,
get_compress_mode((unsigned short *) temp + 1),
encodedBuf, kEncodedBufSize);
if (idn_success != result)
return NS_ERROR_FAILURE;
out.Assign(prefix);
out.Append(encodedBuf);
return NS_OK;
}
示例7:
void
BluetoothScoManager::NotifyAudioManager(const nsAString& aAddress) {
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIObserverService> obs =
do_GetService("@mozilla.org/observer-service;1");
NS_ENSURE_TRUE_VOID(obs);
if (aAddress.IsEmpty()) {
if (NS_FAILED(obs->NotifyObservers(nullptr, BLUETOOTH_SCO_STATUS_CHANGED, nullptr))) {
NS_WARNING("Failed to notify bluetooth-sco-status-changed observsers!");
return;
}
} else {
if (NS_FAILED(obs->NotifyObservers(nullptr, BLUETOOTH_SCO_STATUS_CHANGED, aAddress.BeginReading()))) {
NS_WARNING("Failed to notify bluetooth-sco-status-changed observsers!");
return;
}
}
nsCOMPtr<nsIAudioManager> am =
do_GetService("@mozilla.org/telephony/audiomanager;1");
NS_ENSURE_TRUE_VOID(am);
am->SetForceForUse(am->USE_COMMUNICATION, am->FORCE_BT_SCO);
}
示例8: FontTypeToOutPrecision
void
GDIFontEntry::InitLogFont(const nsAString& aName,
gfxWindowsFontType aFontType)
{
#define CLIP_TURNOFF_FONTASSOCIATION 0x40
mLogFont.lfHeight = -1;
// Fill in logFont structure
mLogFont.lfWidth = 0;
mLogFont.lfEscapement = 0;
mLogFont.lfOrientation = 0;
mLogFont.lfUnderline = FALSE;
mLogFont.lfStrikeOut = FALSE;
mLogFont.lfCharSet = DEFAULT_CHARSET;
mLogFont.lfOutPrecision = FontTypeToOutPrecision(aFontType);
mLogFont.lfClipPrecision = CLIP_TURNOFF_FONTASSOCIATION;
mLogFont.lfQuality = DEFAULT_QUALITY;
mLogFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
// always force lfItalic if we want it. Font selection code will
// do its best to give us an italic font entry, but if no face exists
// it may give us a regular one based on weight. Windows should
// do fake italic for us in that case.
mLogFont.lfItalic = mItalic;
mLogFont.lfWeight = mWeight;
int len = std::min<int>(aName.Length(), LF_FACESIZE - 1);
memcpy(&mLogFont.lfFaceName, aName.BeginReading(), len * sizeof(char16_t));
mLogFont.lfFaceName[len] = '\0';
}
示例9: ParseLinkTypes
void nsStyleLinkElement::ParseLinkTypes(const nsAString& aTypes,
nsTArray<nsString>& aResult)
{
nsAString::const_iterator start, done;
aTypes.BeginReading(start);
aTypes.EndReading(done);
if (start == done)
return;
nsAString::const_iterator current(start);
PRBool inString = !nsCRT::IsAsciiSpace(*current);
nsAutoString subString;
while (current != done) {
if (nsCRT::IsAsciiSpace(*current)) {
if (inString) {
ToLowerCase(Substring(start, current), subString);
aResult.AppendElement(subString);
inString = PR_FALSE;
}
}
else {
if (!inString) {
start = current;
inString = PR_TRUE;
}
}
++current;
}
if (inString) {
ToLowerCase(Substring(start, current), subString);
aResult.AppendElement(subString);
}
}
示例10: ParseLinkTypes
uint32_t nsStyleLinkElement::ParseLinkTypes(const nsAString& aTypes)
{
uint32_t linkMask = 0;
nsAString::const_iterator start, done;
aTypes.BeginReading(start);
aTypes.EndReading(done);
if (start == done)
return linkMask;
nsAString::const_iterator current(start);
bool inString = !nsContentUtils::IsHTMLWhitespace(*current);
nsAutoString subString;
while (current != done) {
if (nsContentUtils::IsHTMLWhitespace(*current)) {
if (inString) {
nsContentUtils::ASCIIToLower(Substring(start, current), subString);
linkMask |= ToLinkMask(subString);
inString = false;
}
}
else {
if (!inString) {
start = current;
inString = true;
}
}
++current;
}
if (inString) {
nsContentUtils::ASCIIToLower(Substring(start, current), subString);
linkMask |= ToLinkMask(subString);
}
return linkMask;
}
示例11: start
/* static */
mozilla::widget::Modifiers
nsDOMUIEvent::ComputeModifierState(const nsAString& aModifiersList)
{
if (aModifiersList.IsEmpty()) {
return 0;
}
// Be careful about the performance. If aModifiersList is too long,
// parsing it needs too long time.
// XXX Should we abort if aModifiersList is too long?
Modifiers modifiers = 0;
nsAString::const_iterator listStart, listEnd;
aModifiersList.BeginReading(listStart);
aModifiersList.EndReading(listEnd);
for (uint32_t i = 0; i < mozilla::ArrayLength(kPairs); i++) {
nsAString::const_iterator start(listStart), end(listEnd);
if (!FindInReadable(NS_ConvertASCIItoUTF16(kPairs[i].name), start, end)) {
continue;
}
if ((start != listStart && !NS_IsAsciiWhitespace(*(--start))) ||
(end != listEnd && !NS_IsAsciiWhitespace(*(end)))) {
continue;
}
modifiers |= kPairs[i].modifier;
}
return modifiers;
}
示例12:
bool
FakeInputStream::CheckTest(nsAString& aResult)
{
return !NS_tstrcmp(aResult.BeginReading(),
NS_ConvertASCIItoUTF16(mTest->mResult).BeginReading())
? true : false;
}
示例13: Distance
nsresult
NS_CopyUnicodeToNative(const nsAString& aInput, nsACString& aOutput)
{
aOutput.Truncate();
nsAString::const_iterator iter, end;
aInput.BeginReading(iter);
aInput.EndReading(end);
// cannot easily avoid intermediate buffer copy.
char temp[4096];
nsNativeCharsetConverter conv;
const char16_t* buf = iter.get();
uint32_t bufLeft = Distance(iter, end);
while (bufLeft) {
char* p = temp;
uint32_t tempLeft = sizeof(temp);
nsresult rv = conv.UnicodeToNative(&buf, &bufLeft, &p, &tempLeft);
if (NS_FAILED(rv)) {
return rv;
}
if (tempLeft < sizeof(temp)) {
aOutput.Append(temp, sizeof(temp) - tempLeft);
}
}
return NS_OK;
}
示例14: toDouble
double Double::toDouble(const nsAString& aSrc)
{
txStringToDouble sink;
nsAString::const_iterator fromBegin, fromEnd;
copy_string(aSrc.BeginReading(fromBegin), aSrc.EndReading(fromEnd), sink);
return sink.getDouble();
}
示例15:
void
nsCSSScanner::Init(const nsAString& aBuffer,
nsIURI* aURI, uint32_t aLineNumber,
nsCSSStyleSheet* aSheet, mozilla::css::Loader* aLoader)
{
NS_PRECONDITION(!mReadPointer, "Should not have an existing input buffer!");
mReadPointer = aBuffer.BeginReading();
mCount = aBuffer.Length();
#ifdef CSS_REPORT_PARSE_ERRORS
// If aURI is the same as mURI, no need to reget mFileName -- it
// shouldn't have changed.
if (aURI != mURI) {
mURI = aURI;
if (aURI) {
aURI->GetSpec(mFileName);
} else {
mFileName.Adopt(NS_strdup("from DOM"));
}
}
#endif // CSS_REPORT_PARSE_ERRORS
mLineNumber = aLineNumber;
// Reset variables that we use to keep track of our progress through the input
mOffset = 0;
mPushbackCount = 0;
mRecording = false;
#ifdef CSS_REPORT_PARSE_ERRORS
mColNumber = 0;
mSheet = aSheet;
mLoader = aLoader;
#endif
}