本文整理汇总了C++中nsCString::AppendLiteral方法的典型用法代码示例。如果您正苦于以下问题:C++ nsCString::AppendLiteral方法的具体用法?C++ nsCString::AppendLiteral怎么用?C++ nsCString::AppendLiteral使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsCString
的用法示例。
在下文中一共展示了nsCString::AppendLiteral方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
static void
HexDump(uint32_t *state, const char *buf, int32_t n, nsCString &result)
{
char temp[16];
const unsigned char *p;
while (n) {
SprintfLiteral(temp, "%08x: ", *state);
result.Append(temp);
*state += HEXDUMP_MAX_ROWS;
p = (const unsigned char *) buf;
int32_t i, row_max = std::min(HEXDUMP_MAX_ROWS, n);
// print hex codes:
for (i = 0; i < row_max; ++i) {
SprintfLiteral(temp, "%02x ", *p++);
result.Append(temp);
}
for (i = row_max; i < HEXDUMP_MAX_ROWS; ++i) {
result.AppendLiteral(" ");
}
// print ASCII glyphs if possible:
p = (const unsigned char *) buf;
for (i = 0; i < row_max; ++i, ++p) {
switch (*p) {
case '<':
result.AppendLiteral("<");
break;
case '>':
result.AppendLiteral(">");
break;
case '&':
result.AppendLiteral("&");
break;
default:
if (*p < 0x7F && *p > 0x1F) {
result.Append(*p);
} else {
result.Append('.');
}
}
}
result.Append('\n');
buf += row_max;
n -= row_max;
}
}
示例2: MapGIOResult
/**
* Create list of infos about objects in opened directory
* Return: NS_OK when list obtained, otherwise error code according
* to failed operation.
*/
nsresult
nsGIOInputStream::DoOpenDirectory()
{
GError *error = nullptr;
GFileEnumerator *f_enum = g_file_enumerate_children(mHandle,
"standard::*,time::*",
G_FILE_QUERY_INFO_NONE,
nullptr,
&error);
if (!f_enum) {
nsresult rv = MapGIOResult(error);
g_warning("Cannot read from directory: %s", error->message);
g_error_free(error);
return rv;
}
// fill list of file infos
GFileInfo *info = g_file_enumerator_next_file(f_enum, nullptr, &error);
while (info) {
mDirList = g_list_append(mDirList, info);
info = g_file_enumerator_next_file(f_enum, nullptr, &error);
}
g_object_unref(f_enum);
if (error) {
g_warning("Error reading directory content: %s", error->message);
nsresult rv = MapGIOResult(error);
g_error_free(error);
return rv;
}
mDirOpen = true;
// Sort list of file infos by using FileInfoComparator function
mDirList = g_list_sort(mDirList, FileInfoComparator);
mDirListPtr = mDirList;
// Write base URL (make sure it ends with a '/')
mDirBuf.AppendLiteral("300: ");
mDirBuf.Append(mSpec);
if (mSpec.get()[mSpec.Length() - 1] != '/')
mDirBuf.Append('/');
mDirBuf.Append('\n');
// Write column names
mDirBuf.AppendLiteral("200: filename content-length last-modified file-type\n");
// Write charset (assume UTF-8)
// XXX is this correct?
mDirBuf.AppendLiteral("301: UTF-8\n");
SetContentTypeOfChannel(APPLICATION_HTTP_INDEX_FORMAT);
return NS_OK;
}
示例3: ReadRecord
nsresult nsVCardAddress::ReadRecord(
nsILineInputStream *aLineStream, nsCString &aRecord, bool *aMore)
{
bool more = true;
nsresult rv;
nsCString line;
aRecord.Truncate();
// read BEGIN:VCARD
rv = aLineStream->ReadLine(line, &more);
if (!line.LowerCaseEqualsLiteral("begin:vcard")) {
IMPORT_LOG0("*** Expected case-insensitive BEGIN:VCARD at start of vCard\n");
rv = NS_ERROR_FAILURE;
*aMore = more;
return rv;
}
aRecord.Append(line);
// read until END:VCARD
do {
if (!more) {
IMPORT_LOG0("*** Expected case-insensitive END:VCARD at start of vCard\n");
rv = NS_ERROR_FAILURE;
break;
}
rv = aLineStream->ReadLine(line, &more);
aRecord.AppendLiteral(MSG_LINEBREAK);
aRecord.Append(line);
} while (!line.LowerCaseEqualsLiteral("end:vcard"));
*aMore = more;
return rv;
}
示例4:
NS_IMETHODIMP
nsMIMEInputStream::AddHeader(const char *aName, const char *aValue)
{
NS_ENSURE_FALSE(mStartedReading, NS_ERROR_FAILURE);
mHeaders.Append(aName);
mHeaders.AppendLiteral(": ");
mHeaders.Append(aValue);
mHeaders.AppendLiteral("\r\n");
// Just in case someone somehow uses our stream, lets at least
// let the stream have a valid pointer. The stream will be properly
// initialized in nsMIMEInputStream::InitStreams
mHeaderStream->ShareData(mHeaders.get(), 0);
return NS_OK;
}
示例5:
/* static */ void
CommonElementAnimationData::LogAsyncAnimationFailure(nsCString& aMessage,
const nsIContent* aContent)
{
if (aContent) {
aMessage.AppendLiteral(" [");
aMessage.Append(nsAtomCString(aContent->Tag()));
nsIAtom* id = aContent->GetID();
if (id) {
aMessage.AppendLiteral(" with id '");
aMessage.Append(nsAtomCString(aContent->GetID()));
aMessage.AppendLiteral("'");
}
aMessage.AppendLiteral("]");
}
printf_stderr(aMessage.get());
}
示例6:
static inline void
GetAuthKey(const char *scheme, const char *host, PRInt32 port, nsCString &key)
{
key.Assign(scheme);
key.AppendLiteral("://");
key.Append(host);
key.Append(':');
key.AppendInt(port);
}
示例7: FormatSizeString
void nsIndexedToHTML::FormatSizeString(int64_t inSize, nsCString& outSizeString)
{
outSizeString.Truncate();
if (inSize > int64_t(0)) {
// round up to the nearest Kilobyte
int64_t upperSize = (inSize + int64_t(1023)) / int64_t(1024);
outSizeString.AppendInt(upperSize);
outSizeString.AppendLiteral(" KB");
}
}
示例8:
/* static */ void
AnimationUtils::LogAsyncAnimationFailure(nsCString& aMessage,
const nsIContent* aContent)
{
if (aContent) {
aMessage.AppendLiteral(" [");
aMessage.Append(nsAtomCString(aContent->NodeInfo()->NameAtom()));
nsIAtom* id = aContent->GetID();
if (id) {
aMessage.AppendLiteral(" with id '");
aMessage.Append(nsAtomCString(aContent->GetID()));
aMessage.Append('\'');
}
aMessage.Append(']');
}
aMessage.Append('\n');
printf_stderr("%s", aMessage.get());
}
示例9: SerializeNamespaces
/**
* If len is one, copies the first element of prefixes into serializedNamespaces.
* If len > 1, copies len strings from prefixes into serializedNamespaces
* as a comma-separated list of quoted strings.
*/
nsresult nsIMAPNamespaceList::SerializeNamespaces(char **prefixes, int len,
nsCString &serializedNamespaces)
{
if (len <= 0)
return NS_OK;
if (len == 1)
{
serializedNamespaces.Assign(prefixes[0]);
return NS_OK;
}
for (int i = 0; i < len; i++)
{
if (i > 0)
serializedNamespaces.AppendLiteral(",");
serializedNamespaces.AppendLiteral("\"");
serializedNamespaces.Append(prefixes[i]);
serializedNamespaces.AppendLiteral("\"");
}
return NS_OK;
}
示例10:
static inline void
GetAuthKey(const char *scheme, const char *host, int32_t port, uint32_t appId, bool inBrowserElement, nsCString &key)
{
key.Truncate();
key.AppendInt(appId);
key.Append(':');
key.AppendInt(inBrowserElement);
key.Append(':');
key.Append(scheme);
key.AppendLiteral("://");
key.Append(host);
key.Append(':');
key.AppendInt(port);
}
示例11: AppendNonAsciiToNCR
static void AppendNonAsciiToNCR(const nsAString& in, nsCString& out)
{
nsAString::const_iterator start, end;
in.BeginReading(start);
in.EndReading(end);
while (start != end) {
if (*start < 128) {
out.Append(*start++);
} else {
out.AppendLiteral("&#x");
out.AppendInt(*start++, 16);
out.Append(';');
}
}
}
示例12: ReadRecord
nsresult nsTextAddress::ReadRecord(nsILineInputStream *aLineStream, nsCString &aLine, bool *aMore)
{
bool more = true;
PRUint32 numQuotes = 0;
nsresult rv;
nsCString line;
// ensure aLine is empty
aLine.Truncate();
do {
if (!more) {
// No more, so we must have an incorrect file.
rv = NS_ERROR_FAILURE;
}
else {
// Read the line and append it
rv = aLineStream->ReadLine(line, &more);
if (NS_SUCCEEDED(rv)) {
if (!aLine.IsEmpty())
aLine.AppendLiteral(MSG_LINEBREAK);
aLine.Append(line);
#ifdef MOZILLA_INTERNAL_API
numQuotes += line.CountChar('"');
#else
const char *begin, *end;
line.BeginReading(&begin, &end);
for (const char *current = begin; current < end; ++current) {
if (*current == '"')
++numQuotes;
}
#endif
}
}
// Continue whilst everything is ok, and we have an odd number of quotes.
} while (NS_SUCCEEDED(rv) && (numQuotes % 2 != 0));
*aMore = more;
return rv;
}
示例13: InitStreams
// set up the internal streams
void nsMIMEInputStream::InitStreams()
{
NS_ASSERTION(!mStartedReading,
"Don't call initStreams twice without rewinding");
mStartedReading = true;
// We'll use the content-length stream to add the final \r\n
if (mAddContentLength) {
uint64_t cl = 0;
if (mData) {
mData->Available(&cl);
}
mContentLength.AssignLiteral("Content-Length: ");
mContentLength.AppendInt(cl);
mContentLength.AppendLiteral("\r\n\r\n");
}
else {
mContentLength.AssignLiteral("\r\n");
}
mCLStream->ShareData(mContentLength.get(), -1);
mHeaderStream->ShareData(mHeaders.get(), -1);
}
示例14: if
//.........这里部分代码省略.........
g_warning("Cannot read from file: %s", error->message);
g_error_free(error);
return rv;
}
*aCountRead = bytes_read;
mBytesRemaining -= *aCountRead;
return NS_OK;
}
else if (mDirOpen) {
// directory read
while (aCount && rv != NS_BASE_STREAM_CLOSED)
{
// Copy data out of our buffer
uint32_t bufLen = mDirBuf.Length() - mDirBufCursor;
if (bufLen)
{
uint32_t n = std::min(bufLen, aCount);
memcpy(aBuf, mDirBuf.get() + mDirBufCursor, n);
*aCountRead += n;
aBuf += n;
aCount -= n;
mDirBufCursor += n;
}
if (!mDirListPtr) // Are we at the end of the directory list?
{
rv = NS_BASE_STREAM_CLOSED;
}
else if (aCount) // Do we need more data?
{
GFileInfo *info = (GFileInfo *) mDirListPtr->data;
// Prune '.' and '..' from directory listing.
const char * fname = g_file_info_get_name(info);
if (fname && fname[0] == '.' &&
(fname[1] == '\0' || (fname[1] == '.' && fname[2] == '\0')))
{
mDirListPtr = mDirListPtr->next;
continue;
}
mDirBuf.AssignLiteral("201: ");
// The "filename" field
nsCString escName;
nsCOMPtr<nsINetUtil> nu = do_GetService(NS_NETUTIL_CONTRACTID);
if (nu && fname) {
nu->EscapeString(nsDependentCString(fname),
nsINetUtil::ESCAPE_URL_PATH, escName);
mDirBuf.Append(escName);
mDirBuf.Append(' ');
}
// The "content-length" field
// XXX truncates size from 64-bit to 32-bit
mDirBuf.AppendInt(int32_t(g_file_info_get_size(info)));
mDirBuf.Append(' ');
// The "last-modified" field
//
// NSPR promises: PRTime is compatible with time_t
// we just need to convert from seconds to microseconds
GTimeVal gtime;
g_file_info_get_modification_time(info, >ime);
PRExplodedTime tm;
PRTime pt = ((PRTime) gtime.tv_sec) * 1000000;
PR_ExplodeTime(pt, PR_GMTParameters, &tm);
{
char buf[64];
PR_FormatTimeUSEnglish(buf, sizeof(buf),
"%a,%%20%d%%20%b%%20%Y%%20%H:%M:%S%%20GMT ", &tm);
mDirBuf.Append(buf);
}
// The "file-type" field
switch (g_file_info_get_file_type(info))
{
case G_FILE_TYPE_REGULAR:
mDirBuf.AppendLiteral("FILE ");
break;
case G_FILE_TYPE_DIRECTORY:
mDirBuf.AppendLiteral("DIRECTORY ");
break;
case G_FILE_TYPE_SYMBOLIC_LINK:
mDirBuf.AppendLiteral("SYMBOLIC-LINK ");
break;
default:
break;
}
mDirBuf.Append('\n');
mDirBufCursor = 0;
mDirListPtr = mDirListPtr->next;
}
}
}
return rv;
}
示例15: while
static void
HandleMailtoSubject(nsCString& aPath) {
// Walk through the string and see if we have a subject already.
bool hasSubject = false;
bool hasParams = false;
int32_t paramSep = aPath.FindChar('?');
while (paramSep != kNotFound && paramSep < (int32_t)aPath.Length()) {
hasParams = true;
// Get the end of the name at the = op. If it is *after* the next &,
// assume that someone made a parameter without an = in it
int32_t nameEnd = aPath.FindChar('=', paramSep+1);
int32_t nextParamSep = aPath.FindChar('&', paramSep+1);
if (nextParamSep == kNotFound) {
nextParamSep = aPath.Length();
}
// If the = op is after the &, this parameter is a name without value.
// If there is no = op, same thing.
if (nameEnd == kNotFound || nextParamSep < nameEnd) {
nameEnd = nextParamSep;
}
if (nameEnd != kNotFound) {
if (Substring(aPath, paramSep+1, nameEnd-(paramSep+1)).
LowerCaseEqualsLiteral("subject")) {
hasSubject = true;
break;
}
}
paramSep = nextParamSep;
}
// If there is no subject, append a preformed subject to the mailto line
if (!hasSubject) {
if (hasParams) {
aPath.Append('&');
} else {
aPath.Append('?');
}
// Get the default subject
nsXPIDLString brandName;
nsresult rv =
nsContentUtils::GetLocalizedString(nsContentUtils::eBRAND_PROPERTIES,
"brandShortName", brandName);
if (NS_FAILED(rv))
return;
const char16_t *formatStrings[] = { brandName.get() };
nsXPIDLString subjectStr;
rv = nsContentUtils::FormatLocalizedString(
nsContentUtils::eFORMS_PROPERTIES,
"DefaultFormSubject",
formatStrings,
subjectStr);
if (NS_FAILED(rv))
return;
aPath.AppendLiteral("subject=");
nsCString subjectStrEscaped;
aPath.Append(NS_EscapeURL(NS_ConvertUTF16toUTF8(subjectStr), esc_Query,
subjectStrEscaped));
}
}