本文整理汇总了C++中NPT_String::Replace方法的典型用法代码示例。如果您正苦于以下问题:C++ NPT_String::Replace方法的具体用法?C++ NPT_String::Replace怎么用?C++ NPT_String::Replace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPT_String
的用法示例。
在下文中一共展示了NPT_String::Replace方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/*----------------------------------------------------------------------
| NPT_DirectoryAppendToPath
+---------------------------------------------------------------------*/
NPT_Result
NPT_DirectoryAppendToPath(NPT_String& path, const char* value)
{
if (!value) return NPT_ERROR_INVALID_PARAMETERS;
NPT_String tmp = value;
// make sure path will end with only one trailing delimiter
path.TrimRight('/');
path.TrimRight('\\');
path += NPT_DIR_DELIMITER_STR;
// make sure value to append doesn't start with delimiters
tmp.TrimLeft('/');
tmp.TrimLeft('\\');
// append value
path += tmp;
// replace delimiters with the proper one for the platform
path.Replace((NPT_DIR_DELIMITER_CHR == '/')?'\\':'/', NPT_DIR_DELIMITER_CHR);
return NPT_SUCCESS;
}
示例2: Create
/*----------------------------------------------------------------------
| NPT_DirectoryCreate
+---------------------------------------------------------------------*/
NPT_Result
NPT_DirectoryCreate(const char* path, bool create_parents)
{
NPT_Result res = NPT_SUCCESS;
NPT_String fullpath = path;
// replace delimiters with the proper one for the platform
fullpath.Replace((NPT_DIR_DELIMITER_CHR == '/')?'\\':'/', NPT_DIR_DELIMITER_CHR);
// remove excessive delimiters
fullpath.TrimRight(NPT_DIR_DELIMITER_CHR);
if (create_parents) {
NPT_String parent_path;
// look for a delimiter from the beginning
int delimiter = fullpath.Find(NPT_DIR_DELIMITER_CHR, 1);
while (delimiter > 0 && NPT_SUCCEEDED(res)) {
// copy the path up to the delimiter
parent_path = fullpath.SubString(0, delimiter);
// create the directory non recursively
res = NPT_DirectoryCreate(parent_path, false);
// look for the next delimiter
delimiter = fullpath.Find(NPT_DIR_DELIMITER_CHR, delimiter + 1);
}
if (NPT_FAILED(res)) return res;
}
// create directory
return NPT_Directory::Create(fullpath);
}
示例3:
/*----------------------------------------------------------------------
| NPT_UrlQuery::UrlDecode
+---------------------------------------------------------------------*/
NPT_String
NPT_UrlQuery::UrlDecode(const char* str)
{
NPT_String decoded = NPT_Uri::PercentDecode(str);
decoded.Replace('+', ' ');
return decoded;
}
示例4: Open
/*----------------------------------------------------------------------
| NPT_LogFileHandler::Log
+---------------------------------------------------------------------*/
void
NPT_LogFileHandler::Log(const NPT_LogRecord& record)
{
if (m_MaxFilesize > 0) {
/* get current file size */
NPT_LargeSize size;
NPT_File::GetSize(m_Filename, size);
/* time to recycle ? */
if (size > m_MaxFilesize) {
/* release stream to force a reopen later
and to be able to rename file */
m_Stream = NULL;
/* rename file using current time */
NPT_TimeStamp now;
NPT_System::GetCurrentTimeStamp(now);
NPT_String suffix = NPT_DateTime(now, true).ToString(NPT_DateTime::FORMAT_W3C);
suffix.Replace(':', '_');
NPT_String new_name = NPT_FilePath::Create(
NPT_FilePath::DirName(m_Filename),
NPT_FilePath::BaseName(m_Filename, false) +
"-" +
suffix +
NPT_FilePath::FileExtension(m_Filename));
NPT_File::Rename(m_Filename, new_name);
}
}
/* try to reopen the file if it failed to open
previously or if we rotated it */
if (m_Stream.IsNull()) {
Open(m_Append);
}
if (m_Stream.AsPointer()) {
NPT_Log::FormatRecordToStream(record, *m_Stream, false, m_FormatFilter);
if (m_Flush) m_Stream->Flush();
}
}
示例5: query
/*----------------------------------------------------------------------
| PLT_FileMediaServer::BuildResourceUri
+---------------------------------------------------------------------*/
NPT_String
PLT_FileMediaServer::BuildResourceUri(const NPT_HttpUrl& base_uri,
const char* host,
const char* file_path)
{
NPT_HttpUrl uri = base_uri;
NPT_HttpUrlQuery query(uri.GetQuery());
NPT_String result;
query.AddField("path", file_path);
if (host) uri.SetHost(host);
uri.SetQuery(query.ToString());
// 360 hack: force inclusion of port
result = uri.ToStringWithDefaultPort(0);
// 360 hack: it removes the query, so we make it look like a path
// and we replace + with urlencoded value of space
result.Replace('?', "%3F");
result.Replace('+', "%20");
return result;
}
示例6: tt
//.........这里部分代码省略.........
0xc3, 0xb8, 0x3a, 0xe1
};
NPT_String b64;
NPT_Base64::Encode(r256_bin, sizeof(r256_bin), b64);
NPT_DataBuffer r256_out;
NPT_Base64::Decode(b64.GetChars(), b64.GetLength(), r256_out);
NPT_ASSERT(r256_out.GetDataSize() == sizeof(r256_bin));
NPT_ASSERT(r256_bin[sizeof(r256_bin)-1] == r256_out.GetData()[sizeof(r256_bin)-1]);
unsigned char random_bytes[] = {
0xc7, 0xee, 0x49, 0x9e, 0x2c, 0x8b, 0x1c, 0x16, 0x9e, 0x7f, 0x30, 0xd0,
0xc6, 0x12, 0x30, 0x80, 0x81, 0xcd, 0x20, 0x20, 0x26, 0xaf, 0x4f, 0xd6,
0xfc, 0x86, 0x2e, 0x85, 0xf3, 0x10, 0x38, 0x2b, 0x0e, 0xbb, 0x80, 0x68,
0xbe, 0xff, 0x1c, 0xdc, 0x72, 0xb5, 0x0d, 0x8f, 0x8e, 0x6c, 0x09, 0x63,
0xba, 0x21, 0x23, 0xb2, 0x24, 0x17, 0xd3, 0x17, 0x69, 0x44, 0x77, 0x11,
0x36, 0x6a, 0x6e, 0xf2, 0x44, 0x87, 0xa1, 0xd3, 0xf3, 0x1f, 0x6c, 0x38,
0x22, 0x4a, 0x44, 0x70, 0x66, 0xef, 0x8c, 0x3a, 0x51, 0xc8, 0xee, 0x85,
0x00, 0x25, 0x93, 0x10, 0x2e, 0x0b, 0x1b, 0x03, 0x94, 0x47, 0x05, 0x22,
0xd0, 0xc4, 0xec, 0x2e, 0xcc, 0xbc, 0xbb, 0x67, 0xfd, 0xec, 0x0e, 0xb1,
0x3f, 0xbc, 0x82, 0xe0, 0xa7, 0x9c, 0xf3, 0xae, 0xbd, 0xb7, 0xab, 0x02,
0xf1, 0xd9, 0x17, 0x4c, 0x9d, 0xeb, 0xe2, 0x00, 0x1e, 0x19, 0x6e, 0xb3,
0xfd, 0x7d, 0xea, 0x49, 0x85, 0x43, 0x2f, 0x56, 0x81, 0x89, 0xba, 0x71,
0x37, 0x10, 0xb5, 0x74, 0xab, 0x90, 0x4d, 0xc4, 0xd1, 0x0d, 0x8d, 0x6f,
0x01, 0xf5, 0x2c, 0xc9, 0x1a, 0x79, 0xa1, 0x41, 0x71, 0x2b, 0xfb, 0xf3,
0xd5, 0xe4, 0x2a, 0xf5, 0xad, 0x80, 0x7a, 0x03, 0xff, 0x5f, 0x45, 0x8c,
0xec, 0x6a, 0x4b, 0x05, 0xe3, 0x65, 0x19, 0x70, 0x05, 0xad, 0xc4, 0xb8,
0x4e, 0x9e, 0x9a, 0x36, 0x4a, 0x86, 0x9d, 0xf5, 0x99, 0xcb, 0x00, 0xb8,
0xb9, 0xa7, 0x86, 0x18, 0xfc, 0x9a, 0xe7, 0x00, 0x6a, 0x67, 0xfa, 0x42,
0x9d, 0xff, 0x4d, 0x7a, 0xe4, 0xe8, 0x03, 0x88, 0xff, 0x60, 0xe1, 0x8d,
0x09, 0x5f, 0x6f, 0xde, 0x6b
};
NPT_Array<unsigned char> random(random_bytes, NPT_ARRAY_SIZE(random_bytes));
t = "x+5JniyLHBaefzDQxhIwgIHNICAmr0/W/IYuhfMQOCsOu4Bovv8c3HK1DY+ObAlj\r\n"
"uiEjsiQX0xdpRHcRNmpu8kSHodPzH2w4IkpEcGbvjDpRyO6FACWTEC4LGwOURwUi\r\n"
"0MTsLsy8u2f97A6xP7yC4Kec8669t6sC8dkXTJ3r4gAeGW6z/X3qSYVDL1aBibpx\r\n"
"NxC1dKuQTcTRDY1vAfUsyRp5oUFxK/vz1eQq9a2AegP/X0WM7GpLBeNlGXAFrcS4\r\n"
"Tp6aNkqGnfWZywC4uaeGGPya5wBqZ/pCnf9NeuToA4j/YOGNCV9v3ms=";
result = NPT_Base64::Decode(t.GetChars(), t.GetLength(), data);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_ASSERT(data.GetDataSize() == 233);
NPT_Array<unsigned char> verif(data.GetData(), data.GetDataSize());
NPT_ASSERT(verif == random);
result = NPT_Base64::Encode(&random[0], random.GetItemCount(), base64, NPT_BASE64_PEM_BLOCKS_PER_LINE);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_ASSERT(base64 == t);
NPT_String t_url = t;
t.Replace('/', '_');
t.Replace('+', '-');
result = NPT_Base64::Encode(&random[0], random.GetItemCount(), base64, NPT_BASE64_PEM_BLOCKS_PER_LINE, true);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_ASSERT(base64 == t);
t = "76768484767685839";
result = NPT_Base64::Decode(t.GetChars(), t.GetLength(), data);
NPT_ASSERT(result == NPT_ERROR_INVALID_FORMAT);
t = "76869=978686";
result = NPT_Base64::Decode(t.GetChars(), t.GetLength(), data);
NPT_ASSERT(result == NPT_ERROR_INVALID_FORMAT);
t = "7686=8978686";
result = NPT_Base64::Decode(t.GetChars(), t.GetLength(), data);
NPT_ASSERT(result == NPT_ERROR_INVALID_FORMAT);
t = "7686==978686";
result = NPT_Base64::Decode(t.GetChars(), t.GetLength(), data);
NPT_ASSERT(result == NPT_ERROR_INVALID_FORMAT);
// test IP address parsing
NPT_IpAddress ip;
NPT_ASSERT(NPT_FAILED(ip.Parse("")));
NPT_ASSERT(NPT_FAILED(ip.Parse("a.b.c.d")));
NPT_ASSERT(NPT_FAILED(ip.Parse("1.2.3.4.5")));
NPT_ASSERT(NPT_FAILED(ip.Parse("1")));
NPT_ASSERT(NPT_FAILED(ip.Parse("1.2.3.4.")));
NPT_ASSERT(NPT_FAILED(ip.Parse("1.2.3.4f")));
NPT_ASSERT(NPT_FAILED(ip.Parse("1.g.3.4")));
NPT_ASSERT(NPT_FAILED(ip.Parse("1.2..3.4")));
NPT_ASSERT(NPT_FAILED(ip.Parse("1.2.300.4")));
NPT_ASSERT(NPT_SUCCEEDED(ip.Parse("1.2.3.4")));
NPT_ASSERT(ip.AsBytes()[0] == 1);
NPT_ASSERT(ip.AsBytes()[1] == 2);
NPT_ASSERT(ip.AsBytes()[2] == 3);
NPT_ASSERT(ip.AsBytes()[3] == 4);
NPT_ASSERT(NPT_SUCCEEDED(ip.Parse("255.255.0.1")));
NPT_ASSERT(ip.AsBytes()[0] == 255);
NPT_ASSERT(ip.AsBytes()[1] == 255);
NPT_ASSERT(ip.AsBytes()[2] == 0);
NPT_ASSERT(ip.AsBytes()[3] == 1);
NPT_ASSERT(NPT_SUCCEEDED(ip.Parse("0.0.0.0")));
NPT_ASSERT(ip.AsBytes()[0] == 0);
NPT_ASSERT(ip.AsBytes()[1] == 0);
NPT_ASSERT(ip.AsBytes()[2] == 0);
NPT_ASSERT(ip.AsBytes()[3] == 0);
return 0;
}
示例7: PlayFile
int CUPnPPlayer::PlayFile(const CFileItem& file, const CPlayerOptions& options, CGUIDialogBusy*& dialog, XbmcThreads::EndTime& timeout)
{
CFileItem item(file);
NPT_Reference<CThumbLoader> thumb_loader;
NPT_Reference<PLT_MediaObject> obj;
NPT_String path(file.GetPath().c_str());
NPT_String tmp, resource;
EMediaControllerQuirks quirks = EMEDIACONTROLLERQUIRKS_NONE;
NPT_CHECK_POINTER_LABEL_SEVERE(m_delegate, failed);
if (file.IsVideoDb())
thumb_loader = NPT_Reference<CThumbLoader>(new CVideoThumbLoader());
else if (item.IsMusicDb())
thumb_loader = NPT_Reference<CThumbLoader>(new CMusicThumbLoader());
obj = BuildObject(item, path, false, thumb_loader, NULL, CUPnP::GetServer(), UPnPPlayer);
if(obj.IsNull()) goto failed;
NPT_CHECK_LABEL_SEVERE(PLT_Didl::ToDidl(*obj, "", tmp), failed_todidl);
tmp.Insert(didl_header, 0);
tmp.Append(didl_footer);
quirks = GetMediaControllerQuirks(m_delegate->m_device.AsPointer());
if (quirks & EMEDIACONTROLLERQUIRKS_X_MKV)
{
for (NPT_Cardinal i=0; i< obj->m_Resources.GetItemCount(); i++) {
if (obj->m_Resources[i].m_ProtocolInfo.GetContentType().Compare("video/x-matroska") == 0) {
CLog::Log(LOGDEBUG, "CUPnPPlayer::PlayFile(%s): applying video/x-mkv quirk", file.GetPath().c_str());
NPT_String protocolInfo = obj->m_Resources[i].m_ProtocolInfo.ToString();
protocolInfo.Replace(":video/x-matroska:", ":video/x-mkv:");
obj->m_Resources[i].m_ProtocolInfo = PLT_ProtocolInfo(protocolInfo);
}
}
}
/* The resource uri's are stored in the Didl. We must choose the best resource
* for the playback device */
NPT_Cardinal res_index;
NPT_CHECK_LABEL_SEVERE(m_control->FindBestResource(m_delegate->m_device, *obj, res_index), failed_findbestresource);
// get the transport info to evaluate the TransportState to be able to
// determine whether we first need to call Stop()
timeout.Set(timeout.GetInitialTimeoutValue());
NPT_CHECK_LABEL_SEVERE(m_control->GetTransportInfo(m_delegate->m_device
, m_delegate->m_instance
, m_delegate), failed_gettransportinfo);
NPT_CHECK_LABEL_SEVERE(WaitOnEvent(m_delegate->m_traevnt, timeout, dialog), failed_gettransportinfo);
if (m_delegate->m_trainfo.cur_transport_state != "NO_MEDIA_PRESENT" &&
m_delegate->m_trainfo.cur_transport_state != "STOPPED")
{
timeout.Set(timeout.GetInitialTimeoutValue());
NPT_CHECK_LABEL_SEVERE(m_control->Stop(m_delegate->m_device
, m_delegate->m_instance
, m_delegate), failed_stop);
NPT_CHECK_LABEL_SEVERE(WaitOnEvent(m_delegate->m_resevent, timeout, dialog), failed_stop);
NPT_CHECK_LABEL_SEVERE(m_delegate->m_resstatus, failed_stop);
}
timeout.Set(timeout.GetInitialTimeoutValue());
NPT_CHECK_LABEL_SEVERE(m_control->SetAVTransportURI(m_delegate->m_device
, m_delegate->m_instance
, obj->m_Resources[res_index].m_Uri
, (const char*)tmp
, m_delegate), failed_setavtransporturi);
NPT_CHECK_LABEL_SEVERE(WaitOnEvent(m_delegate->m_resevent, timeout, dialog), failed_setavtransporturi);
NPT_CHECK_LABEL_SEVERE(m_delegate->m_resstatus, failed_setavtransporturi);
timeout.Set(timeout.GetInitialTimeoutValue());
NPT_CHECK_LABEL_SEVERE(m_control->Play(m_delegate->m_device
, m_delegate->m_instance
, "1"
, m_delegate), failed_play);
NPT_CHECK_LABEL_SEVERE(WaitOnEvent(m_delegate->m_resevent, timeout, dialog), failed_play);
NPT_CHECK_LABEL_SEVERE(m_delegate->m_resstatus, failed_play);
/* wait for PLAYING state */
timeout.Set(timeout.GetInitialTimeoutValue());
do {
NPT_CHECK_LABEL_SEVERE(m_control->GetTransportInfo(m_delegate->m_device
, m_delegate->m_instance
, m_delegate), failed_waitplaying);
{ CSingleLock lock(m_delegate->m_section);
if(m_delegate->m_trainfo.cur_transport_state == "PLAYING"
|| m_delegate->m_trainfo.cur_transport_state == "PAUSED_PLAYBACK")
break;
if(m_delegate->m_trainfo.cur_transport_state == "STOPPED"
&& m_delegate->m_trainfo.cur_transport_status != "OK")
{
CLog::Log(LOGERROR, "UPNP: CUPnPPlayer::OpenFile - remote player signalled error %s", file.GetPath().c_str());
return NPT_FAILURE;
}
}
//.........这里部分代码省略.........
示例8: tt
//.........这里部分代码省略.........
0x22, 0x4a, 0x44, 0x70, 0x66, 0xef, 0x8c, 0x3a, 0x51, 0xc8, 0xee, 0x85,
0x00, 0x25, 0x93, 0x10, 0x2e, 0x0b, 0x1b, 0x03, 0x94, 0x47, 0x05, 0x22,
0xd0, 0xc4, 0xec, 0x2e, 0xcc, 0xbc, 0xbb, 0x67, 0xfd, 0xec, 0x0e, 0xb1,
0x3f, 0xbc, 0x82, 0xe0, 0xa7, 0x9c, 0xf3, 0xae, 0xbd, 0xb7, 0xab, 0x02,
0xf1, 0xd9, 0x17, 0x4c, 0x9d, 0xeb, 0xe2, 0x00, 0x1e, 0x19, 0x6e, 0xb3,
0xfd, 0x7d, 0xea, 0x49, 0x85, 0x43, 0x2f, 0x56, 0x81, 0x89, 0xba, 0x71,
0x37, 0x10, 0xb5, 0x74, 0xab, 0x90, 0x4d, 0xc4, 0xd1, 0x0d, 0x8d, 0x6f,
0x01, 0xf5, 0x2c, 0xc9, 0x1a, 0x79, 0xa1, 0x41, 0x71, 0x2b, 0xfb, 0xf3,
0xd5, 0xe4, 0x2a, 0xf5, 0xad, 0x80, 0x7a, 0x03, 0xff, 0x5f, 0x45, 0x8c,
0xec, 0x6a, 0x4b, 0x05, 0xe3, 0x65, 0x19, 0x70, 0x05, 0xad, 0xc4, 0xb8,
0x4e, 0x9e, 0x9a, 0x36, 0x4a, 0x86, 0x9d, 0xf5, 0x99, 0xcb, 0x00, 0xb8,
0xb9, 0xa7, 0x86, 0x18, 0xfc, 0x9a, 0xe7, 0x00, 0x6a, 0x67, 0xfa, 0x42,
0x9d, 0xff, 0x4d, 0x7a, 0xe4, 0xe8, 0x03, 0x88, 0xff, 0x60, 0xe1, 0x8d,
0x09, 0x5f, 0x6f, 0xde, 0x6b
};
NPT_Array<unsigned char> random(random_bytes, NPT_ARRAY_SIZE(random_bytes));
t = "x+5JniyLHBaefzDQxhIwgIHNICAmr0/W/IYuhfMQOCsOu4Bovv8c3HK1DY+ObAlj\r\n"
"uiEjsiQX0xdpRHcRNmpu8kSHodPzH2w4IkpEcGbvjDpRyO6FACWTEC4LGwOURwUi\r\n"
"0MTsLsy8u2f97A6xP7yC4Kec8669t6sC8dkXTJ3r4gAeGW6z/X3qSYVDL1aBibpx\r\n"
"NxC1dKuQTcTRDY1vAfUsyRp5oUFxK/vz1eQq9a2AegP/X0WM7GpLBeNlGXAFrcS4\r\n"
"Tp6aNkqGnfWZywC4uaeGGPya5wBqZ/pCnf9NeuToA4j/YOGNCV9v3ms=";
result = NPT_Base64::Decode(t.GetChars(), t.GetLength(), data);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_ASSERT(data.GetDataSize() == 233);
NPT_Array<unsigned char> verif(data.GetData(), data.GetDataSize());
NPT_ASSERT(verif == random);
result = NPT_Base64::Encode(&random[0], random.GetItemCount(), base64, NPT_BASE64_PEM_BLOCKS_PER_LINE);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_ASSERT(base64 == t);
NPT_String t_url = t;
t.Replace('/', '_');
t.Replace('+', '-');
result = NPT_Base64::Encode(&random[0], random.GetItemCount(), base64, NPT_BASE64_PEM_BLOCKS_PER_LINE, true);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_ASSERT(base64 == t);
t = "76768484767685839";
result = NPT_Base64::Decode(t.GetChars(), t.GetLength(), data);
NPT_ASSERT(result == NPT_ERROR_INVALID_FORMAT);
t = "76869=978686";
result = NPT_Base64::Decode(t.GetChars(), t.GetLength(), data);
NPT_ASSERT(result == NPT_ERROR_INVALID_FORMAT);
t = "7686=8978686";
result = NPT_Base64::Decode(t.GetChars(), t.GetLength(), data);
NPT_ASSERT(result == NPT_ERROR_INVALID_FORMAT);
t = "7686==978686";
result = NPT_Base64::Decode(t.GetChars(), t.GetLength(), data);
NPT_ASSERT(result == NPT_ERROR_INVALID_FORMAT);
// test IP address parsing
NPT_IpAddress ip;
NPT_ASSERT(NPT_FAILED(ip.Parse("")));
NPT_ASSERT(NPT_FAILED(ip.Parse("a.b.c.d")));
NPT_ASSERT(NPT_FAILED(ip.Parse("1.2.3.4.5")));
NPT_ASSERT(NPT_FAILED(ip.Parse("1")));
NPT_ASSERT(NPT_FAILED(ip.Parse("1.2.3.4.")));
NPT_ASSERT(NPT_FAILED(ip.Parse("1.2.3.4f")));
NPT_ASSERT(NPT_FAILED(ip.Parse("1.g.3.4")));
NPT_ASSERT(NPT_FAILED(ip.Parse("1.2..3.4")));
NPT_ASSERT(NPT_FAILED(ip.Parse("1.2.300.4")));