本文整理汇总了C++中nsCString::Truncate方法的典型用法代码示例。如果您正苦于以下问题:C++ nsCString::Truncate方法的具体用法?C++ nsCString::Truncate怎么用?C++ nsCString::Truncate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsCString
的用法示例。
在下文中一共展示了nsCString::Truncate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetStringFromProp
BOOL CMapiApi::GetStringFromProp( LPSPropValue pVal, nsCString& val, BOOL delVal)
{
BOOL bResult = TRUE;
if ( pVal && (PROP_TYPE( pVal->ulPropTag) == PT_STRING8))
val = pVal->Value.lpszA;
else if ( pVal && (PROP_TYPE( pVal->ulPropTag) == PT_UNICODE))
LossyCopyUTF16toASCII((PRUnichar *) pVal->Value.lpszW, val);
else if (pVal && (PROP_TYPE( pVal->ulPropTag) == PT_NULL))
val.Truncate();
else if (pVal && (PROP_TYPE( pVal->ulPropTag) == PT_ERROR)) {
val.Truncate();
bResult = FALSE;
}
else {
if (pVal) {
MAPI_TRACE1( "GetStringFromProp: invalid value, expecting string - %d\n", (int) PROP_TYPE( pVal->ulPropTag));
}
else {
MAPI_TRACE0( "GetStringFromProp: invalid value, expecting string, got null pointer\n");
}
val.Truncate();
bResult = FALSE;
}
if (pVal && delVal)
MAPIFreeBuffer( pVal);
return( bResult);
}
示例2: ExtractMetaCharset
void ExtractMetaCharset(const wchar_t* body, int bodySz, /*out*/nsCString& charset)
{
charset.Truncate();
const wchar_t* body_end = body+bodySz;
const wchar_t str_eohd[] = L"/head";
const wchar_t *str_eohd_end = str_eohd+sizeof(str_eohd)/sizeof(str_eohd[0])-1;
const wchar_t* eohd_pos = std::search(body, body_end, str_eohd, str_eohd_end,
CaseInsensitiveComp);
if (eohd_pos == body_end) // No header!
return;
const wchar_t str_chset[] = L"charset=";
const wchar_t *str_chset_end =
str_chset + sizeof(str_chset)/sizeof(str_chset[0])-1;
const wchar_t* chset_pos = std::search(body, eohd_pos, str_chset,
str_chset_end, CaseInsensitiveComp);
if (chset_pos == eohd_pos) // No charset!
return;
chset_pos += 8;
// remove everything from the string after the next ; or " or space,
// whichever comes first.
// The inital sting looks something like
// <META content="text/html; charset=utf-8" http-equiv=Content-Type>
// <META content="text/html; charset=utf-8;" http-equiv=Content-Type>
// <META content="text/html; charset=utf-8 ;" http-equiv=Content-Type>
// <META content="text/html; charset=utf-8 " http-equiv=Content-Type>
const wchar_t term[] = L";\" ", *term_end= term+sizeof(term)/sizeof(term[0])-1;
const wchar_t* chset_end = std::find_first_of(chset_pos, eohd_pos, term,
term_end);
if (chset_end != eohd_pos)
LossyCopyUTF16toASCII(Substring(chset_pos, chset_end), charset);
}
示例3: ExtractNoteField
void nsEudoraAddress::ExtractNoteField( nsCString& note, nsCString& value, const char *pFieldName)
{
value.Truncate();
nsCString field("<");
field.Append( pFieldName);
field.Append( ':');
/*
this is a bit of a cheat, but there's no reason it won't work
fine for us, even better than Eudora in some cases!
*/
PRInt32 idx = note.Find( field);
if (idx != -1) {
idx += field.Length();
PRInt32 endIdx = note.FindChar( '>', idx);
if (endIdx == -1)
endIdx = note.Length() - 1;
note.Mid( value, idx, endIdx - idx);
idx -= field.Length();
nsCString tempL;
if (idx)
note.Left( tempL, idx);
nsCString tempR;
note.Right( tempR, note.Length() - endIdx - 1);
note = tempL;
note.Append( tempR);
}
}
示例4: namespaceURI
static nsresult
ExtractAttribute(nsIDOMNode* aNode,
const char* aAttribute,
const char* aNamespaceURI,
nsCString& aValue)
{
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aNode);
MOZ_ASSERT(element);
// Find the named URI attribute on the (element) node and store
// a reference to the URI that maps onto a local file name
nsCOMPtr<nsIDOMMozNamedAttrMap> attrMap;
nsresult rv = element->GetAttributes(getter_AddRefs(attrMap));
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
NS_ConvertASCIItoUTF16 namespaceURI(aNamespaceURI);
NS_ConvertASCIItoUTF16 attribute(aAttribute);
nsCOMPtr<nsIDOMAttr> attr;
rv = attrMap->GetNamedItemNS(namespaceURI, attribute, getter_AddRefs(attr));
NS_ENSURE_SUCCESS(rv, rv);
if (attr) {
nsAutoString value;
rv = attr->GetValue(value);
NS_ENSURE_SUCCESS(rv, rv);
aValue = NS_ConvertUTF16toUTF8(value);
} else {
aValue.Truncate();
}
return NS_OK;
}
示例5: extractAttributeValue
// takes a string like ?size=32&contentType=text/html and returns a new string
// containing just the attribute value. i.e you could pass in this string with
// an attribute name of 'size=', this will return 32
// Assumption: attribute pairs in the string are separated by '&'.
void extractAttributeValue(const char * searchString, const char * attributeName, nsCString& result)
{
//NS_ENSURE_ARG_POINTER(extractAttributeValue);
result.Truncate();
if (searchString && attributeName)
{
// search the string for attributeName
uint32_t attributeNameSize = strlen(attributeName);
const char * startOfAttribute = PL_strcasestr(searchString, attributeName);
if (startOfAttribute &&
( *(startOfAttribute-1) == '?' || *(startOfAttribute-1) == '&') )
{
startOfAttribute += attributeNameSize; // skip over the attributeName
if (*startOfAttribute) // is there something after the attribute name
{
const char * endofAttribute = strchr(startOfAttribute, '&');
if (endofAttribute)
result.Assign(Substring(startOfAttribute, endofAttribute));
else
result.Assign(startOfAttribute);
} // if we have a attribute value
} // if we have a attribute name
} // if we got non-null search string and attribute name values
}
示例6: ConvertLineBreaks
// i18n helper routines
nsresult
nsEncodingFormSubmission::EncodeVal(const nsAString& aStr, nsCString& aOut,
bool aHeaderEncode)
{
if (mEncoder && !aStr.IsEmpty()) {
aOut.Truncate();
nsresult rv = mEncoder->Convert(PromiseFlatString(aStr).get(),
getter_Copies(aOut));
NS_ENSURE_SUCCESS(rv, rv);
}
else {
// fall back to UTF-8
CopyUTF16toUTF8(aStr, aOut);
}
if (aHeaderEncode) {
aOut.Adopt(nsLinebreakConverter::
ConvertLineBreaks(aOut.get(),
nsLinebreakConverter::eLinebreakAny,
nsLinebreakConverter::eLinebreakSpace));
aOut.ReplaceSubstring(NS_LITERAL_CSTRING("\""),
NS_LITERAL_CSTRING("\\\""));
}
return NS_OK;
}
示例7: GetNextFilterLine
int32_t nsMsgBodyHandler::GetNextFilterLine(nsCString &buf)
{
// m_nextHdr always points to the next header in the list....the list is NULL terminated...
uint32_t numBytesCopied = 0;
if (m_headersSize > 0)
{
// #mscott. Ugly hack! filter headers list have CRs & LFs inside the NULL delimited list of header
// strings. It is possible to have: To NULL CR LF From. We want to skip over these CR/LFs if they start
// at the beginning of what we think is another header.
while (m_headersSize > 0 && (m_headers[0] == '\r' || m_headers[0] == '\n' || m_headers[0] == ' ' || m_headers[0] == '\0'))
{
m_headers++; // skip over these chars...
m_headersSize--;
}
if (m_headersSize > 0)
{
numBytesCopied = strlen(m_headers) + 1 ;
buf.Assign(m_headers);
m_headers += numBytesCopied;
// be careful...m_headersSize is unsigned. Don't let it go negative or we overflow to 2^32....*yikes*
if (m_headersSize < numBytesCopied)
m_headersSize = 0;
else
m_headersSize -= numBytesCopied; // update # bytes we have read from the headers list
return (int32_t) numBytesCopied;
}
}
else if (m_headersSize == 0) {
buf.Truncate();
}
return -1;
}
示例8: nsUnescapeCount
nsresult
nsGopherContentStream::ParseTypeAndSelector(char &type, nsCString &selector)
{
nsCAutoString buffer;
nsresult rv = mChannel->URI()->GetPath(buffer); // unescaped down below
if (NS_FAILED(rv))
return rv;
// No path given
if (buffer[0] == '\0' || (buffer[0] == '/' && buffer[1] == '\0')) {
type = '1';
selector.Truncate();
} else {
NS_ENSURE_STATE(buffer[1] != '\0');
type = buffer[1]; // Ignore leading '/'
// Do it this way in case selector contains embedded nulls after
// unescaping.
char *sel = buffer.BeginWriting() + 2;
PRInt32 count = nsUnescapeCount(sel);
selector.Assign(sel, count);
// NOTE: FindCharInSet cannot be used to search for a null byte.
if (selector.FindCharInSet("\t\n\r") != kNotFound ||
selector.FindChar('\0') != kNotFound) {
// gopher selectors cannot containt tab, cr, lf, or \0
return NS_ERROR_MALFORMED_URI;
}
}
return NS_OK;
}
示例9:
nsresult
nsAboutCache::ParseURI(nsIURI * uri, nsCString &deviceID)
{
//
// about:cache[?device=string]
//
nsresult rv;
deviceID.Truncate();
nsCAutoString path;
rv = uri->GetPath(path);
if (NS_FAILED(rv)) return rv;
nsACString::const_iterator start, valueStart, end;
path.BeginReading(start);
path.EndReading(end);
valueStart = end;
if (!FindInReadable(NS_LITERAL_CSTRING("?device="), start, valueStart))
return NS_OK;
deviceID.Assign(Substring(valueStart, end));
return NS_OK;
}
示例10: 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;
}
示例11: 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());
}
示例12: LOG
void
nsUrlClassifierDBServiceWorker::ResetUpdate()
{
LOG(("ResetUpdate"));
mUpdateWait = 0;
mUpdateStatus = NS_OK;
mUpdateObserver = nsnull;
mUpdateClientKey.Truncate();
}
示例13:
void nsEudoraWin32::GetServerAndUserName( const char *pSection, const char *pIni, nsCString& serverName, nsCString& userName, char *pBuff)
{
DWORD valSize;
int idx;
nsCString tStr;
serverName.Truncate();
userName.Truncate();
valSize = ::GetPrivateProfileString( pSection, "PopServer", "", pBuff, kIniValueSize, pIni);
if (valSize)
serverName = pBuff;
else
{
valSize = ::GetPrivateProfileString( pSection, "POPAccount", "", pBuff, kIniValueSize, pIni);
if (valSize)
{
serverName = pBuff;
idx = serverName.FindChar( '@');
if (idx != -1)
{
serverName.Right( tStr, serverName.Length() - idx - 1);
serverName = tStr;
}
}
}
valSize = ::GetPrivateProfileString( pSection, "LoginName", "", pBuff, kIniValueSize, pIni);
if (valSize)
userName = pBuff;
else
{
valSize = ::GetPrivateProfileString( pSection, "POPAccount", "", pBuff, kIniValueSize, pIni);
if (valSize)
{
userName = pBuff;
idx = userName.FindChar( '@');
if (idx != -1)
{
userName.Left( tStr, idx);
userName = tStr;
}
}
}
}
示例14: ClearRequestHeader
NS_IMETHODIMP
nsIncrementalDownload::AsyncOnChannelRedirect(nsIChannel *oldChannel,
nsIChannel *newChannel,
uint32_t flags,
nsIAsyncVerifyRedirectCallback *cb)
{
// In response to a redirect, we need to propagate the Range header. See bug
// 311595. Any failure code returned from this function aborts the redirect.
nsCOMPtr<nsIHttpChannel> http = do_QueryInterface(oldChannel);
NS_ENSURE_STATE(http);
nsCOMPtr<nsIHttpChannel> newHttpChannel = do_QueryInterface(newChannel);
NS_ENSURE_STATE(newHttpChannel);
NS_NAMED_LITERAL_CSTRING(rangeHdr, "Range");
nsresult rv = ClearRequestHeader(newHttpChannel);
if (NS_FAILED(rv))
return rv;
// If we didn't have a Range header, then we must be doing a full download.
nsAutoCString rangeVal;
http->GetRequestHeader(rangeHdr, rangeVal);
if (!rangeVal.IsEmpty()) {
rv = newHttpChannel->SetRequestHeader(rangeHdr, rangeVal, false);
NS_ENSURE_SUCCESS(rv, rv);
}
// A redirection changes the validator
mPartialValidator.Truncate();
if (mCacheBust) {
newHttpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Cache-Control"),
NS_LITERAL_CSTRING("no-cache"), false);
newHttpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Pragma"),
NS_LITERAL_CSTRING("no-cache"), false);
}
// Prepare to receive callback
mRedirectCallback = cb;
mNewRedirectChannel = newChannel;
// Give the observer a chance to see this redirect notification.
nsCOMPtr<nsIChannelEventSink> sink = do_GetInterface(mObserver);
if (sink) {
rv = sink->AsyncOnChannelRedirect(oldChannel, newChannel, flags, this);
if (NS_FAILED(rv)) {
mRedirectCallback = nullptr;
mNewRedirectChannel = nullptr;
}
return rv;
}
(void) OnRedirectVerifyCallback(NS_OK);
return NS_OK;
}
示例15: Substring
void
nsMorkReader::NormalizeValue(nsCString &aValue) const
{
PRUint32 len = aValue.Length();
if (len == 0) {
return;
}
const nsCSubstring &str = Substring(aValue, 1, len - 1);
char c = aValue[0];
if (c == '^') {
if (!mValueMap.Get(str, &aValue)) {
aValue.Truncate(0);
}
} else if (c == '=') {
aValue.Assign(str);
} else {
aValue.Truncate(0);
}
}