本文整理汇总了C++中StringBuffer::replaceAll方法的典型用法代码示例。如果您正苦于以下问题:C++ StringBuffer::replaceAll方法的具体用法?C++ StringBuffer::replaceAll怎么用?C++ StringBuffer::replaceAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuffer
的用法示例。
在下文中一共展示了StringBuffer::replaceAll方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadValueFromFile
String AbstractContextI::loadValueFromFile(const String& fileurl) const throw (Exception)
{
StringBuffer buf;
buf->append(fileurl);
if (0 != buf->indexOf(L"file://")) throw NamingException(WITHDETAILS(L"Expected url starting wtih 'file://' but found : " + fileurl));
bool mustprependworkingdirectory = L'/' != buf->charAt(7);
StringBuffer filename;
if (L':' == buf->charAt(9)) // windows filepath
{
filename->append(buf->substring(8));
filename = filename->replaceAll(L"/", L"\\");
}
else
{
filename->append(buf->substring(7));
}
String fullpath;
if (mustprependworkingdirectory)
{
Anything value;
lookup(L"/env/jlj_context_working_directory", value);
String workingdirectory = value;
fullpath = workingdirectory + filename;
}
else
{
fullpath = filename->toString();
}
if (verboseOutput()) cout << "JNDI context : Reading from file : " << fullpath << endl;
InputStream file = new FileInputStreamI(fullpath);
UTF8String content;
file->read(content, 0);
file->close();
return content->toString();
}
示例2: parseHeaders
int MailMessage::parseHeaders(StringBuffer &rfcHeaders) {
ArrayList lines;
const StringBuffer *line;
StringBuffer strReceived;
bool receivedExtracted = false;
LOG.debug("parseHeaders START");
// Join header parts using \t or 8 blank
StringBuffer joinlinetab("\t");
rfcHeaders.replaceAll(joinlinetab, " ");
StringBuffer joinlinespaces(newline);
joinlinespaces+=" "; // 8 blanks
rfcHeaders.replaceAll(joinlinespaces, " ");
rfcHeaders.split(lines, newline);
// importance is set to "0" by default. Then there isn't anything modification
// in the header, at the end of the loop the importance will be set to "3", default normal
importance = "0";
for ( line=(StringBuffer *)lines.front();
line;
line=(StringBuffer *)lines.next() ) {
if( *line == "\r" )
break;
// The first empty line marks the end of the header section
if( line->empty() ){
break;
}
// Process the headers
if( line->ifind(TO) == 0 ){
to = MailMessage::decodeHeader(line->substr(TO_LEN));
}
else if( line->ifind(FROM) == 0 ) {
from = MailMessage::decodeHeader(line->substr(FROM_LEN));
}
else if( line->ifind(CC) == 0 ) {
cc = MailMessage::decodeHeader(line->substr(CC_LEN));
}
else if( line->ifind(BCC) == 0 ) {
bcc = MailMessage::decodeHeader(line->substr(BCC_LEN));
}
else if ( line->ifind(DATE) == 0 ) {
//subjectParsing = false;
if( date.parseRfc822(line->substr(DATE_LEN)) ) {
LOG.error("Error parsing date");
return 500;
}
}
else if( line->ifind(SUBJECT) == 0 ) {
subject = MailMessage::decodeHeader(line->substr(SUBJECT_LEN));
LOG.debug("SUBJECT: %s", subject.c_str());
}
else if( line->ifind(ENCODING) == 0 ) { // it is here for single part only
body.setEncoding(line->substr(ENCODING_LEN));
}
else if(line->ifind(MIMEVERS) == 0 ) {
mimeVersion = line->substr(MIMEVERS_LEN);
}
else if(line->ifind(MESSAGEID) == 0 ) {
messageId = line->substr(MESSAGEID_LEN);
}
else if(line->ifind(IMPORTANCE) == 0 ) {
StringBuffer data = line->substr(IMPORTANCE_LEN);
data.lowerCase();
importance = convertImportance(data);
}
else if(line->ifind(X_PRIORITY) == 0 ) {
if (importance == "0") {
StringBuffer data = line->substr(X_PRIORITY_LEN);
data.lowerCase();
importance = convertXPriority(data);
}
}
else if( line->ifind(MIMETYPE) == 0 ) {
StringBuffer sb = getTokenValue(line, MIMETYPE);
if (sb.length() > 0)
contentType = sb;
sb.reset();
sb = getTokenValue(line, "boundary=", false);
if (sb.length() > 0) {
boundary = sb;
} else {
body.setCharset(getTokenValue(line, CT_CHARSET));
}
/*
size_t len = line->find(";") - MIMETYPE_LEN ;
contentType = line->substr(MIMETYPE_LEN, len);
//.........这里部分代码省略.........
示例3: stringdup
/**
* Format a mailmessage in a RFC2822 string
*/
char * MailMessage::format() {
// If the message is empty, return null
if ( empty() ) {
LOG.debug("MailMessage::format: empty message.");
return 0;
}
StringBuffer ret;
LOG.debug("MailMessage::format START");
if ( contentType.empty() ) {
if ( attachments.size() ) {
contentType = "multipart/mixed";
}
else {
contentType = body.getMimeType();
if (headers.size() > 0) {
StringBuffer *line; int j = 0;
for (line=(StringBuffer *)headers.front(); line; line=(StringBuffer *)headers.next() ) {
if (strstr(line->c_str(), "format=") != 0
|| strstr(line->c_str(),"reply-type=") != 0 ) {
contentType.append("; ");
line->replaceAll(";", " ");
contentType.append(line->c_str());
headers.removeElementAt(j);
j--;
}
j++;
}
}
}
}
if ( mimeVersion.empty() ) {
mimeVersion = "1.0";
}
// Add generics headers
ret.join((ArrayList &)headers, NL);
// Add parsed headers
ret += MIMEVERS; ret += mimeVersion; ret += NL;
ret += MESSAGEID; ret += messageId; ret += NL;
LOG.debug("MailMessage: From: %s\n", from.c_str());
ret += FROM; ret += from; ret += NL;
ret += TO; ret += to; ret += NL;
if (cc.length() ) {
ret += CC; ret += cc; ret += NL;
}
if (bcc.length() ) {
ret += BCC; ret += bcc; ret += NL;
}
ret += DATE; ret += date.formatRfc822(); ret += NL;
ret += SUBJECT;
ret += encodeHeader(subject);
ret += NL;
// add priority
ret += IMPORTANCE; ret += convertForImportance(importance); ret += NL;
ret += X_PRIORITY; ret += convertForXPriority(importance); ret += NL;
ret += MIMETYPE; ret += contentType; ret+= "; ";
if (contentType.ifind(MULTIPART) != StringBuffer::npos ){
if ( boundary.empty() ) {
generateBoundary(boundary);
}
ret += "\n boundary=\""; ret += boundary;
ret += "\"\n\nThis is a multi-part message in MIME format.\n";
// Prepare a string with the boundary on a line alone
StringBuffer bound = "\n--"; bound += boundary;
// Body
ret += bound; ret += NL;
ret += formatBodyPart(body);
ret += bound;
// Attachments
const BodyPart *part;
for ( part=(const BodyPart *)attachments.front();
part;
part=(BodyPart *)attachments.next() ) {
ret += NL;
ret += formatBodyPart(*part);
ret += bound;
}
ret += "--\n";
}
else {
// Body
if(body.getCharset())
ret += CT_CHARSET; ret += body.getCharset(); ret += NL;
if( body.getEncoding() )
ret += ENCODING; ret += body.getEncoding();
// end of headers
//.........这里部分代码省略.........
示例4: getBodyPart
/**
* Get the next bodypart from the message body string.
*
* @param rfcBody (in) - message content
* @param boundary (in) - mime boundary string
* @param ret (out) - parsed BodyPart
* @param next (i/o) - offset of the new boundary
* @param isAttach (in) - says if the current body part is an attachment or not
*/
static bool getBodyPart(StringBuffer &rfcBody, StringBuffer &boundary,
BodyPart &ret, size_t &next, bool isAttach)
{
LOG.debug("getBodyPart START");
StringBuffer newline;
// The part starts on the next line
size_t begin = findNewLine(rfcBody, next);
if (begin == StringBuffer::npos)
return false;
// find the end of the part
next = rfcBody.find(boundary, begin);
if (next == StringBuffer::npos)
return false;
// get the part
StringBuffer part = rfcBody.substr(begin, next-begin);
// If it is a multipart alternative part, get the text part only.
// check only until the first new line not on all the message (it could be
// a message inside another message)
size_t headers_len = getHeadersLen(part, newline);
StringBuffer headers_part = part.substr(0, headers_len);
if (headers_part.ifind("Content-Type: multipart/alternative") != StringBuffer::npos) {
if(part.ifind("Content-Type: multipart/alternative") != StringBuffer::npos) {
size_t b_pos = part.ifind("boundary=");
if( b_pos != StringBuffer::npos ) {
size_t begin = part.find("=\"", b_pos) + 2 ;
size_t end = part.find("\"", begin) ;
StringBuffer inner_boundary("\n--");
inner_boundary += part.substr( begin, end-begin );
begin = part.find(inner_boundary, end);
begin += inner_boundary.length();
end = part.find(inner_boundary, begin);
if (begin != StringBuffer::npos && end != StringBuffer::npos) {
part = part.substr(begin, end-begin);
LOG.debug("Bodypart is multipart/alternative: "
"getting first alternative only: \n%s\n", part.c_str() );
}
}
}
}
// Split headers and body
size_t hdrlen = getHeadersLen(part, newline);
// Get headers
StringBuffer headers = part.substr(0, hdrlen);
// Join header parts using \t or 8 blank
StringBuffer joinlinetab("\t");
headers.replaceAll(joinlinetab, " ");
StringBuffer joinlinespaces(newline);
joinlinespaces+=" "; // 8 blanks
headers.replaceAll(joinlinespaces, " ");
ArrayList lines;
const StringBuffer *line;
// parse the bodypart headers
headers.split(lines, newline);
for ( line=(StringBuffer *)lines.front();
line;
line=(StringBuffer *)lines.next() ) {
if( *line == "\r" )
continue;
// The first empty line marks the end of the header section
//if( line->empty() ){
// break;
//}
// Process the headers
if( line->ifind(MIMETYPE) == 0 ) { // it must at the beginning
ret.setMimeType(getTokenValue(line, MIMETYPE));
if (line->ifind(CT_NAME) != StringBuffer::npos) {
ret.setName(MailMessage::decodeHeader(getTokenValue(line, CT_NAME,false)));
}
if (line->ifind(CT_CHARSET) != StringBuffer::npos ) {
ret.setCharset(getTokenValue(line, CT_CHARSET));
}
}
else if( line->ifind(DISPOSITION) == 0 ) {
ret.setDisposition( getTokenValue(line, DISPOSITION));
if (line->ifind(CD_FILENAME) != StringBuffer::npos ) {
ret.setFilename( MailMessage::decodeHeader( getTokenValue(line, CD_FILENAME, false) ) );
}
}
else if( line->ifind(ENCODING) == 0 ) {
ret.setEncoding( getTokenValue(line, ENCODING));
}
//.........这里部分代码省略.........
示例5: decodeHeader
StringBuffer MailMessage::decodeHeader(StringBuffer line) {
if (!line || line.empty()) {
return line;
}
size_t startPos = 0;
StringBuffer ret;
StringBuffer charset;
while( (startPos = line.find("=?", startPos)) != StringBuffer::npos) {
// Skip the '=?'
startPos += 2;
// Find the first '?'
size_t firstMark = line.find("?", startPos);
if (firstMark == StringBuffer::npos) {
LOG.error("Invalid encoded header");
return line;
}
// Find the second '?'
size_t secondMark = line.find("?", firstMark+1);
if (secondMark == StringBuffer::npos) {
LOG.error("Invalid encoded header");
return line;
}
// Find the final '?='
size_t endPos = line.find("?=", secondMark+1);
if (endPos == StringBuffer::npos) {
LOG.error("Invalid encoded header");
return line;
}
charset = line.substr(startPos, firstMark - startPos);
StringBuffer encoding = line.substr(firstMark+1, secondMark - (firstMark + 1));
StringBuffer text = line.substr(secondMark+1, endPos - (secondMark + 1));
if (encoding.icmp("Q")) {
// quoted-printable
text.replaceAll("_", " ");
char* dec = qp_decode(text);
if (startPos >= 2 && ret.length() == 0) {
ret += line.substr(0, startPos - 2);
}
ret += dec;
delete [] dec;
}
else if (encoding.icmp("B")){
// base64
char* dec = new char[text.length()];
int len = b64_decode((void *)dec, text);
dec[len]=0;
if (startPos >= 2 && ret.length() == 0) {
ret += line.substr(0, startPos - 2);
}
ret += dec;
delete [] dec;
}
startPos = endPos;
}
if (ret.length() == 0) {
ret += line;
}
WCHAR* wret = toWideChar(ret, charset);
ret.set(NULL);
char* t = toMultibyte(wret);
ret.set(t);
if (wret) {delete [] wret;}
if (t) {delete [] t;}
return ret;
}
示例6: OnCbnSelchangePicturesComboSynctype
void CPicturesSettings::OnCbnSelchangePicturesComboSynctype()
{
// Supported data format
StringBuffer supportedData;
CString ss(" "), ss1;
ss1.LoadString(IDS_SUPPORTED_FORMAT);
ss.Append(ss1);
CString And;
And.LoadString(IDS_STRING_AND);
StringBuffer and(" ");
and.append(ConvertToChar(And));
and.append(" ");
StringBuffer data = ssconf->getProperty(PROPERTY_EXTENSION);
if (data.empty() == false) {
supportedData = ConvertToChar(ss);
StringBuffer data = ssconf->getProperty(PROPERTY_EXTENSION);
data.upperCase();
supportedData.append(data);
int val = supportedData.rfind(",.");
if (val != StringBuffer::npos) {
supportedData.replace(",.", and.c_str(), val);
}
supportedData.replaceAll(",.",", ");
supportedData.replaceAll(".","");
supportedData.append(".");
}
CString suppData = supportedData;
int index = 0;
if (lstSyncType.GetCount() > 1) {
index = lstSyncType.GetCurSel();
} else {
// Fixed, 1 synctype only, get from config.
index = getSyncTypeIndex(ssconf->getSync());
}
CString s1;
switch (index) {
case 0:
s1.LoadString(IDS_TWO_WAY_LABEL_PICT_SUMMARY);
s1.Append(suppData);
SetDlgItemText(IDC_PICTURES_SYNC_DIRECTION_LABEL, s1);
break;
case 1:
s1.LoadString(IDS_DOWNLOAD_ONLY_LABEL_PICT_SUMMARY);
s1.Append(suppData);
SetDlgItemText(IDC_PICTURES_SYNC_DIRECTION_LABEL, s1);
break;
case 2:
s1.LoadString(IDS_UPLOAD_ONLY_LABEL_PICT_SUMMARY);
s1.Append(suppData);
SetDlgItemText(IDC_PICTURES_SYNC_DIRECTION_LABEL, s1);
break;
}
}
示例7: OnCbnSelchangeVideosComboSynctype
void CVideosSettings::OnCbnSelchangeVideosComboSynctype()
{
// Supported data format
StringBuffer supportedData;
CString ss(" "), ss1;
ss1.LoadString(IDS_SUPPORTED_FORMAT);
ss.Append(ss1);
CString And;
And.LoadString(IDS_STRING_AND);
StringBuffer and(" ");
and.append(ConvertToChar(And));
and.append(" ");
StringBuffer data = ssconf->getProperty(PROPERTY_EXTENSION);
if (data.empty() == false) {
supportedData = ConvertToChar(ss);
StringBuffer data = ssconf->getProperty(PROPERTY_EXTENSION);
data.upperCase();
supportedData.append(data);
int val = supportedData.rfind(",.");
if (val != StringBuffer::npos) {
supportedData.replace(",.", and.c_str(), val);
}
supportedData.replaceAll(",.",", ");
supportedData.replaceAll(".","");
supportedData.append(".");
}
/*
CString s2;
s2.LoadString(IDS_MEDIA_HUB_VIDEO_MAX_SIZE);
StringBuffer s, sss;
s = ConvertToChar(s2);
sss.sprintf(s.c_str(), (int)SAPI_MAX_VIDEO_SIZE/1024/1024);
supportedData.append(" ");
supportedData.append(sss);
*/
CString s2;
s2.LoadString(IDS_MEDIA_HUB_VIDEO_MAX_SIZE);
WCHAR tmp[1024];
wsprintf(tmp, s2.GetBuffer(), (int)SAPI_MAX_VIDEO_SIZE/1024/1024);
wstring w1 = tmp;
WCHAR* tmp2 = toWideChar(supportedData.c_str());
wstring w2 = tmp2;
delete [] tmp2;
w2.append(L" ");
w2.append(w1);
CString suppData(w2.c_str()); //supportedData;
int index = 0;
if (lstSyncType.GetCount() > 1) {
index = lstSyncType.GetCurSel();
} else {
// Fixed, 1 synctype only, get from config.
index = getSyncTypeIndex(ssconf->getSync());
}
CString s1;
switch (index) {
case 0:
s1.LoadString(IDS_TWO_WAY_LABEL_VIDEO_SUMMARY);
s1.Append(suppData);
SetDlgItemText(IDC_VIDEOS_SYNC_DIRECTION_LABEL, s1);
break;
case 1:
s1.LoadString(IDS_DOWNLOAD_ONLY_LABEL_VIDEO_SUMMARY);
s1.Append(suppData);
SetDlgItemText(IDC_VIDEOS_SYNC_DIRECTION_LABEL, s1);
break;
case 2:
s1.LoadString(IDS_UPLOAD_ONLY_LABEL_VIDEO_SUMMARY);
s1.Append(suppData);
SetDlgItemText(IDC_VIDEOS_SYNC_DIRECTION_LABEL, s1);
break;
}
}