Пример #1
0
/*----------------------------------------------------------------------
|   PLT_DeviceData::SetURLBase
+---------------------------------------------------------------------*/
NPT_Result
PLT_DeviceData::SetURLBase(NPT_HttpUrl& url) 
{
    // only http scheme supported
    m_URLBase.SetScheme(url.GetScheme());

    // update port if any
    if (url.GetPort() != NPT_URL_INVALID_PORT) m_URLBase.SetPort(url.GetPort());

    // update host if any
    if (!url.GetHost().IsEmpty()) m_URLBase.SetHost(url.GetHost());

    // update path
    NPT_String path = url.GetPath();

    // remove trailing file according to RFC 2396
    if (!path.EndsWith("/")) {
        int index = path.ReverseFind('/');
        if (index < 0) return NPT_FAILURE;
        path.SetLength(index+1);
    }
    m_URLBase.SetPath(path, true);

    return NPT_SUCCESS;
}    
Пример #2
0
/*----------------------------------------------------------------------
|   NPT_FilePath::BaseName
+---------------------------------------------------------------------*/
NPT_String 
NPT_FilePath::BaseName(const char* path, bool with_extension /* = true */)
{
    NPT_String result = path;
    int separator = result.ReverseFind(Separator);
    if (separator >= 0) {
        result = path+separator+NPT_StringLength(Separator);
    } 

    if (!with_extension) {
        int dot = result.ReverseFind('.');
        if (dot >= 0) {
            result.SetLength(dot);
        }
    }

    return result;
}
Пример #3
0
/*----------------------------------------------------------------------
|   NPT_FilePath::BaseName
+---------------------------------------------------------------------*/
NPT_String 
NPT_FilePath::BaseName(const char* path)
{
    NPT_String result = path;
    int separator = result.ReverseFind(Separator);
    if (separator >= 0) {
        result = path+separator+NPT_StringLength(Separator);
    } 

    return result;
}
Пример #4
0
/*----------------------------------------------------------------------
|   NPT_FilePath::FileExtension
+---------------------------------------------------------------------*/
NPT_String 
NPT_FilePath::FileExtension(const char* path)
{
    NPT_String result = path;
    int separator = result.ReverseFind('.');
    if (separator >= 0) {
        result = path+separator;
    } else {
        result.SetLength(0);
    }

    return result;
}
Пример #5
0
/*----------------------------------------------------------------------
|   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;
}
Пример #6
0
/*----------------------------------------------------------------------
|   NPT_FilePath::DirectoryName
+---------------------------------------------------------------------*/
NPT_String 
NPT_FilePath::DirectoryName(const char* path)
{
    NPT_String result = path;
    int separator = result.ReverseFind(Separator);
    if (separator >= 0) {
        if (separator == 0) {
            result.SetLength(NPT_StringLength(Separator));
        } else {
            result.SetLength(separator);
        }
    } else {
        result.SetLength(0);
    } 

    return result;
}