本文整理汇总了C++中NPT_String::SubString方法的典型用法代码示例。如果您正苦于以下问题:C++ NPT_String::SubString方法的具体用法?C++ NPT_String::SubString怎么用?C++ NPT_String::SubString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPT_String
的用法示例。
在下文中一共展示了NPT_String::SubString方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
/*----------------------------------------------------------------------
| CUPnPDirectory::GetFriendlyName
+---------------------------------------------------------------------*/
const char*
CUPnPDirectory::GetFriendlyName(const char* url)
{
NPT_String path = url;
if (!path.EndsWith("/")) path += "/";
if (path.Left(7).Compare("upnp://", true) != 0) {
return NULL;
} else if (path.Compare("upnp://", true) == 0) {
return "UPnP Media Servers (Auto-Discover)";
}
// look for nextslash
int next_slash = path.Find('/', 7);
if (next_slash == -1)
return NULL;
NPT_String uuid = path.SubString(7, next_slash-7);
NPT_String object_id = path.SubString(next_slash+1, path.GetLength()-next_slash-2);
// look for device
PLT_DeviceDataReference* device;
const NPT_Lock<PLT_DeviceMap>& devices = CUPnP::GetInstance()->m_MediaBrowser->GetMediaServers();
if (NPT_FAILED(devices.Get(uuid, device)) || device == NULL)
return NULL;
return (const char*)(*device)->GetFriendlyName();
}
示例2: if
/*----------------------------------------------------------------------
| CUPnPDirectory::GetFriendlyName
+---------------------------------------------------------------------*/
const char*
CUPnPDirectory::GetFriendlyName(const char* url)
{
NPT_String path = url;
if (!path.EndsWith("/")) path += "/";
if (path.Left(7).Compare("upnp://", true) != 0) {
return NULL;
} else if (path.Compare("upnp://", true) == 0) {
return "UPnP Media Servers (Auto-Discover)";
}
// look for nextslash
int next_slash = path.Find('/', 7);
if (next_slash == -1)
return NULL;
NPT_String uuid = path.SubString(7, next_slash-7);
NPT_String object_id = path.SubString(next_slash+1, path.GetLength()-next_slash-2);
// look for device
PLT_DeviceDataReference device;
if(!FindDeviceWait(CUPnP::GetInstance(), uuid, device))
return NULL;
return (const char*)device->GetFriendlyName();
}
示例3:
/*----------------------------------------------------------------------
| CMediaCrawler::SplitObjectId
+---------------------------------------------------------------------*/
NPT_Result
CMediaCrawler::SplitObjectId(const NPT_String& object_id, NPT_String& server_uuid, NPT_String& server_object_id)
{
// reset output params
server_uuid = "";
server_object_id = "";
if (object_id.GetLength() == 0 || object_id[0] != '0')
return NPT_ERROR_INVALID_FORMAT;
if (object_id.GetLength() > 1) {
if (object_id[1] != '/') return NPT_ERROR_INVALID_FORMAT;
server_uuid = object_id.SubString(2);
// look for next delimiter
int index = server_uuid.Find('/');
if (index >= 0) {
server_object_id = server_uuid.SubString(index+1);
server_uuid.SetLength(index);
}
}
return NPT_SUCCESS;
}
示例4: 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);
}
示例5: while
void
GPAC_MediaController::OnMSStateVariablesChanged(PLT_Service* service, NPT_List<PLT_StateVariable*>* vars)
{
GPAC_MediaServerItem *ms = NULL;
gf_mx_p(m_ControlPointLock);
u32 i, count;
count = gf_list_count(m_MediaServers);
for (i=0; i<count; i++) {
GPAC_MediaServerItem *ms = (GPAC_MediaServerItem *) gf_list_get(m_MediaServers, i);
if (ms->m_UUID==service->GetDevice()->GetUUID()) {
break;
}
ms = NULL;
}
if (!ms) {
gf_mx_v(m_ControlPointLock);
return;
}
PLT_StateVariable* var = PLT_StateVariable::Find(*vars, "ContainerUpdateIDs");
if (var) {
// variable found, parse value
NPT_String value = var->GetValue();
NPT_String item_id, update_id;
int index;
while (value.GetLength()) {
// look for container id
index = value.Find(',');
if (index < 0) break;
item_id = value.Left(index);
value = value.SubString(index+1);
// look for update id
if (value.GetLength()) {
index = value.Find(',');
update_id = (index<0)?value:value.Left(index);
value = (index<0)?"":value.SubString(index+1);
m_pUPnP->ContainerChanged(ms->m_device, item_id, update_id);
}
}
}
gf_mx_v(m_ControlPointLock);
}
示例6: if
/*----------------------------------------------------------------------
| CUPnPVirtualPathDirectory::SplitPath
+---------------------------------------------------------------------*/
bool
CUPnPVirtualPathDirectory::SplitPath(const char* object_id, NPT_String& share_name, NPT_String& path)
{
int index = 0;
NPT_String id = object_id;
id.TrimRight("/");
// reset output params first
share_name = "";
path = "";
if (id.StartsWith("virtualpath://upnproot")) {
index = 22;
} else if (id.StartsWith("virtualpath://upnpmusic")) {
index = 23;
} else if (id.StartsWith("virtualpath://upnpvideo")) {
index = 23;
} else if (id.StartsWith("virtualpath://upnppictures")) {
index = 26;
} else {
return false;
}
// nothing to split
if (id.GetLength() <= (NPT_Cardinal)index) {
return true;
}
// invalid id!
if (id[index] != '/') {
return false;
}
// look for share
index = id.Find('/', index+1);
share_name = id.SubString(0, (index==-1)?id.GetLength():index);
if (index >= 0) {
path = id.SubString(index+1);
}
return true;
}
示例7: lock
/*----------------------------------------------------------------------
| PLT_SyncMediaBrowser::OnMSStateVariablesChanged
+---------------------------------------------------------------------*/
void
PLT_SyncMediaBrowser::OnMSStateVariablesChanged(PLT_Service* service,
NPT_List<PLT_StateVariable*>* vars)
{
NPT_AutoLock lock(m_MediaServers);
PLT_DeviceDataReference device;
const NPT_List<PLT_DeviceMapEntry*>::Iterator it =
m_MediaServers.GetEntries().Find(PLT_DeviceMapFinderByUUID(service->GetDevice()->GetUUID()));
if (!it) return; // device with this service has gone away
device = (*it)->GetValue();
PLT_StateVariable* var = PLT_StateVariable::Find(*vars, "ContainerUpdateIDs");
if (var) {
// variable found, parse value
NPT_String value = var->GetValue();
NPT_String item_id, update_id;
int index;
while (value.GetLength()) {
// look for container id
index = value.Find(',');
if (index < 0) break;
item_id = value.Left(index);
value = value.SubString(index+1);
// look for update id
if (value.GetLength()) {
index = value.Find(',');
update_id = (index<0)?value:value.Left(index);
value = (index<0)?"":value.SubString(index+1);
// clear cache for that device
if (m_UseCache) m_Cache.Clear(device->GetUUID(), item_id);
// notify listener
if (m_ContainerListener) m_ContainerListener->OnContainerChanged(device, item_id, update_id);
}
}
}
}
示例8:
/*----------------------------------------------------------------------
| PLT_Didl::ParseTimeStamp
+---------------------------------------------------------------------*/
NPT_Result
PLT_Didl::ParseTimeStamp(const NPT_String& timestamp, NPT_UInt32& seconds)
{
// assume a timestamp in the format HH:MM:SS.FFF
int separator;
NPT_String str = timestamp;
NPT_UInt32 value;
// reset output params first
seconds = 0;
// remove milliseconds first if any
if ((separator = str.ReverseFind('.')) != -1) {
str = str.Left(separator);
}
// look for next separator
if ((separator = str.ReverseFind(':')) == -1) return NPT_FAILURE;
// extract seconds
NPT_CHECK_WARNING(str.SubString(separator+1).ToInteger(value));
seconds = value;
str = str.Left(separator);
// look for next separator
if ((separator = str.ReverseFind(':')) == -1) return NPT_FAILURE;
// extract minutes
NPT_CHECK_WARNING(str.SubString(separator+1).ToInteger(value));
seconds += 60*value;
str = str.Left(separator);
// extract hours
NPT_CHECK_WARNING(str.ToInteger(value));
seconds += 3600*value;
return NPT_SUCCESS;
}
示例9: onHttpRequest
bool SimpleDMS::onHttpRequest(AbortableTask *task, const FrontEnd::InterfaceContext *ifctx, const NPT_String& relPath, const FrontEnd::RequestContext& reqCtx, const NPT_HttpRequest *req, NPT_HttpResponse& resp, NPT_InputStream *inputStream, HttpOutput *httpOutput)
{
MediaStore::FileDetail detail;
bool found = false;
if (relPath.StartsWith("dms/")) {
found = m_store->findFileDetail(relPath.SubString(4), detail);
}
if (found) {
if (detail.m_type == MediaStore::FileDetail::ALAsset) {
serveIOSAsset(task, detail, reqCtx, req, resp, httpOutput);
} else {
serveFile(task, detail.m_path, detail.m_mimeType, reqCtx, req, resp, httpOutput);
}
} else {
setStatusCode(resp, 404);
httpOutput->writeResponseHeader(resp);
}
return true;
}
示例10: pItem
/*----------------------------------------------------------------------
| CUPnPDirectory::GetDirectory
+---------------------------------------------------------------------*/
bool
CUPnPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
{
CUPnP* upnp = CUPnP::GetInstance();
/* upnp should never be cached, it has internal cache */
items.SetCacheToDisc(CFileItemList::CACHE_NEVER);
// We accept upnp://devuuid/[item_id/]
NPT_String path = strPath.c_str();
if (!path.StartsWith("upnp://", true)) {
return false;
}
if (path.Compare("upnp://", true) == 0) {
upnp->StartClient();
// root -> get list of devices
const NPT_Lock<PLT_DeviceDataReferenceList>& devices = upnp->m_MediaBrowser->GetMediaServers();
NPT_List<PLT_DeviceDataReference>::Iterator device = devices.GetFirstItem();
while (device) {
NPT_String name = (*device)->GetFriendlyName();
NPT_String uuid = (*device)->GetUUID();
CFileItemPtr pItem(new CFileItem((const char*)name));
pItem->SetPath(CStdString((const char*) "upnp://" + uuid + "/"));
pItem->m_bIsFolder = true;
pItem->SetArt("thumb", (const char*)(*device)->GetIconUrl("image/png"));
items.Add(pItem);
++device;
}
} else {
if (!path.EndsWith("/")) path += "/";
// look for nextslash
int next_slash = path.Find('/', 7);
NPT_String uuid = (next_slash==-1)?path.SubString(7):path.SubString(7, next_slash-7);
NPT_String object_id = (next_slash==-1)?"":path.SubString(next_slash+1);
object_id.TrimRight("/");
if (object_id.GetLength()) {
CStdString tmp = (char*) object_id;
CURL::Decode(tmp);
object_id = tmp;
}
// try to find the device with wait on startup
PLT_DeviceDataReference device;
if (!FindDeviceWait(upnp, uuid, device))
goto failure;
// issue a browse request with object_id
// if object_id is empty use "0" for root
object_id = object_id.IsEmpty()?"0":object_id;
// remember a count of object classes
std::map<NPT_String, int> classes;
// just a guess as to what types of files we want
bool video = true;
bool audio = true;
bool image = true;
m_strFileMask.TrimLeft("/");
if (!m_strFileMask.IsEmpty()) {
video = m_strFileMask.Find(".wmv") >= 0;
audio = m_strFileMask.Find(".wma") >= 0;
image = m_strFileMask.Find(".jpg") >= 0;
}
// special case for Windows Media Connect and WMP11 when looking for root
// We can target which root subfolder we want based on directory mask
if (object_id == "0" && ((device->GetFriendlyName().Find("Windows Media Connect", 0, true) >= 0) ||
(device->m_ModelName == "Windows Media Player Sharing"))) {
// look for a specific type to differentiate which folder we want
if (audio && !video && !image) {
// music
object_id = "1";
} else if (!audio && video && !image) {
// video
object_id = "2";
} else if (!audio && !video && image) {
// pictures
object_id = "3";
}
}
#ifdef DISABLE_SPECIALCASE
// same thing but special case for XBMC
if (object_id == "0" && ((device->m_ModelName.Find("XBMC", 0, true) >= 0) ||
(device->m_ModelName.Find("Xbox Media Center", 0, true) >= 0))) {
// look for a specific type to differentiate which folder we want
if (audio && !video && !image) {
// music
object_id = "virtualpath://upnpmusic";
//.........这里部分代码省略.........
示例11: parseRangeHeader
bool parseRangeHeader(const NPT_String& text, NPT_UInt64 totalLength, NPT_UInt64& offset, NPT_UInt64& length)
{
if (!text.StartsWith("bytes=")) {
return false;
}
if (text.Find(',') >= 0) {
// multiple ranges, currently unsupported
return false;
}
int sep = text.Find('-', 6);
if (sep < 0) {
return false;
}
NPT_String p1 = text.SubString(6, sep - 6);
NPT_String p2 = text.SubString(sep + 1);
NPT_UInt64 v1, v2;
if (p1.IsEmpty()) {
if (p2.IsEmpty()) {
return false;
} else {
if (NPT_FAILED(NPT_ParseInteger64(p2, v2))) {
return false;
}
if (v2 <= totalLength) {
offset = totalLength - v2;
length = v2;
} else {
offset = 0;
length = totalLength;
}
}
} else {
if (NPT_FAILED(NPT_ParseInteger64(p1, v1))) {
return false;
}
if (v1 >= totalLength) {
return false;
}
if (p2.IsEmpty()) {
offset = v1;
length = totalLength - offset;
} else {
if (NPT_FAILED(NPT_ParseInteger64(p2, v2))) {
return false;
}
if (v2 >= totalLength) {
return false;
}
if (v2 < v1) {
return false;
}
offset = v1;
length = v2 - v1 + 1;
}
}
return true;
}
示例12: pItem
/*----------------------------------------------------------------------
| CUPnPDirectory::GetDirectory
+---------------------------------------------------------------------*/
bool
CUPnPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
{
CUPnP* upnp = CUPnP::GetInstance();
/* upnp should never be cached, it has internal cache */
items.SetCacheToDisc(CFileItemList::CACHE_NEVER);
// We accept upnp://devuuid/[item_id/]
NPT_String path = strPath.c_str();
if (!path.StartsWith("upnp://", true)) {
return false;
}
if (path.Compare("upnp://", true) == 0) {
upnp->StartClient();
// root -> get list of devices
const NPT_Lock<PLT_DeviceDataReferenceList>& devices = upnp->m_MediaBrowser->GetMediaServers();
NPT_List<PLT_DeviceDataReference>::Iterator device = devices.GetFirstItem();
while (device) {
NPT_String name = (*device)->GetFriendlyName();
NPT_String uuid = (*device)->GetUUID();
CFileItemPtr pItem(new CFileItem((const char*)name));
pItem->SetPath(CStdString((const char*) "upnp://" + uuid + "/"));
pItem->m_bIsFolder = true;
pItem->SetThumbnailImage((const char*)(*device)->GetIconUrl("image/jpeg"));
items.Add(pItem);
++device;
}
} else {
if (!path.EndsWith("/")) path += "/";
// look for nextslash
int next_slash = path.Find('/', 7);
NPT_String uuid = (next_slash==-1)?path.SubString(7):path.SubString(7, next_slash-7);
NPT_String object_id = (next_slash==-1)?"":path.SubString(next_slash+1);
object_id.TrimRight("/");
if (object_id.GetLength()) {
CStdString tmp = (char*) object_id;
CURL::Decode(tmp);
object_id = tmp;
}
// try to find the device with wait on startup
PLT_DeviceDataReference device;
if (!FindDeviceWait(upnp, uuid, device))
goto failure;
// issue a browse request with object_id
// if object_id is empty use "0" for root
object_id = object_id.IsEmpty()?"0":object_id;
// remember a count of object classes
std::map<NPT_String, int> classes;
// just a guess as to what types of files we want
bool video = true;
bool audio = true;
bool image = true;
m_strFileMask.TrimLeft("/");
if (!m_strFileMask.IsEmpty()) {
video = m_strFileMask.Find(".wmv") >= 0;
audio = m_strFileMask.Find(".wma") >= 0;
image = m_strFileMask.Find(".jpg") >= 0;
}
// special case for Windows Media Connect and WMP11 when looking for root
// We can target which root subfolder we want based on directory mask
if (object_id == "0" && ((device->GetFriendlyName().Find("Windows Media Connect", 0, true) >= 0) ||
(device->m_ModelName == "Windows Media Player Sharing"))) {
// look for a specific type to differentiate which folder we want
if (audio && !video && !image) {
// music
object_id = "1";
} else if (!audio && video && !image) {
// video
object_id = "2";
} else if (!audio && !video && image) {
// pictures
object_id = "3";
}
}
#ifdef DISABLE_SPECIALCASE
// same thing but special case for XBMC
if (object_id == "0" && ((device->m_ModelName.Find("XBMC", 0, true) >= 0) ||
(device->m_ModelName.Find("Xbox Media Center", 0, true) >= 0))) {
// look for a specific type to differentiate which folder we want
if (audio && !video && !image) {
// music
object_id = "virtualpath://upnpmusic";
//.........这里部分代码省略.........
示例13: pItem
/*----------------------------------------------------------------------
| CUPnPDirectory::GetDirectory
+---------------------------------------------------------------------*/
bool
CUPnPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
{
CGUIDialogProgress* dlgProgress = NULL;
CUPnP* upnp = CUPnP::GetInstance();
/* upnp should never be cached, it has internal cache */
items.SetCacheToDisc(CFileItemList::CACHE_NEVER);
// start client if it hasn't been done yet
bool client_started = upnp->IsClientStarted();
upnp->StartClient();
// We accept upnp://devuuid/[item_id/]
NPT_String path = strPath.c_str();
if (!path.StartsWith("upnp://", true)) {
return false;
}
if (path.Compare("upnp://", true) == 0) {
// root -> get list of devices
const NPT_Lock<PLT_DeviceMap>& devices = upnp->m_MediaBrowser->GetMediaServers();
const NPT_List<PLT_DeviceMapEntry*>& entries = devices.GetEntries();
NPT_List<PLT_DeviceMapEntry*>::Iterator entry = entries.GetFirstItem();
while (entry) {
PLT_DeviceDataReference device = (*entry)->GetValue();
NPT_String name = device->GetFriendlyName();
NPT_String uuid = (*entry)->GetKey();
CFileItemPtr pItem(new CFileItem((const char*)name));
pItem->m_strPath = (const char*) "upnp://" + uuid + "/";
pItem->m_bIsFolder = true;
pItem->SetThumbnailImage((const char*)device->GetIconUrl("image/jpeg"));
items.Add(pItem);
++entry;
}
} else {
if (!path.EndsWith("/")) path += "/";
// look for nextslash
int next_slash = path.Find('/', 7);
NPT_String uuid = (next_slash==-1)?path.SubString(7):path.SubString(7, next_slash-7);
NPT_String object_id = (next_slash==-1)?"":path.SubString(next_slash+1);
object_id.TrimRight("/");
if (object_id.GetLength()) {
CStdString tmp = (char*) object_id;
CUtil::UrlDecode(tmp);
object_id = tmp;
}
// look for device in our list
// (and wait for it to respond for 5 secs if we're just starting upnp client)
NPT_TimeStamp watchdog;
NPT_System::GetCurrentTimeStamp(watchdog);
watchdog += 5.f;
PLT_DeviceDataReference* device;
for (;;) {
const NPT_Lock<PLT_DeviceMap>& devices = upnp->m_MediaBrowser->GetMediaServers();
if (NPT_SUCCEEDED(devices.Get(uuid, device)) && device)
break;
// fail right away if device not found and upnp client was already running
if (client_started)
goto failure;
// otherwise check if we've waited long enough without success
NPT_TimeStamp now;
NPT_System::GetCurrentTimeStamp(now);
if (now > watchdog)
goto failure;
// sleep a bit and try again
NPT_System::Sleep(NPT_TimeInterval(1, 0));
}
// issue a browse request with object_id
// if object_id is empty use "0" for root
object_id = object_id.IsEmpty()?"0":object_id;
// just a guess as to what types of files we want
bool video = true;
bool audio = true;
bool image = true;
m_strFileMask.TrimLeft("/");
if (!m_strFileMask.IsEmpty()) {
video = m_strFileMask.Find(".wmv") >= 0;
audio = m_strFileMask.Find(".wma") >= 0;
image = m_strFileMask.Find(".jpg") >= 0;
}
// special case for Windows Media Connect and WMP11 when looking for root
// We can target which root subfolder we want based on directory mask
//.........这里部分代码省略.........