⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chxavramparser.cpp

📁 symbian 下的helix player源代码
💻 CPP
字号:
/*============================================================================*
 *
 * (c) 1995-2002 RealNetworks, Inc. Patents pending. All rights reserved.
 *
 *============================================================================*/
 
/*
 *  Description: 
 *
 */
#include <ctype.h>
#include "hxstring.h"
#include "chxavurlrep.h"
#include "chxavramparser.h"
#include "chxavurlrep.h"
#include "chxavurlfix.h"
#include "chxavparseiterator.h"
#include "chxavramparser.h"

class URLParser {
public:
    URLParser();
    bool Parse(const CHXString& line);
    bool Valid() const;
    void Reset();
    const CHXAvURLRep& Value() const;
    
private:
    CHXAvURLRep m_url;
};

inline
static
CHXString Trim(const CHXString& line)
{
    int len = line.GetLength();

    // trim left
    const char* s = line;
    while (*s && isspace(*s))
    {
       ++s;
       --len;
    }

    // trim right
    const char* p = strrchr(s, '#');
    if (p)
    len = p - s;

    while (len > 0 && isspace(s[len-1]))
    --len;
   
    return CHXString((const char*)s, len);
}

URLParser::URLParser()
    : m_url("")
{}

bool URLParser::Parse(const CHXString& line)
{
    CHXString trimmed = Trim(line);

    // Make sure the line contains characters
    // and has '://' which should be present in
    // all RAM file URLs
    if ((trimmed.GetLength() > 0) &&
	(strstr((const char*)trimmed, "://")))
    {
        CHXAvURLRep url(trimmed);
	
        if (!url.Valid())
        {
	    // Perhaps invalid because it has back-slashes instead of forward slashes
            if(stricmp(url.Protocol(), "file") == 0)
            {
                CHXString strNewPath = url.Path();
                if( strNewPath.FindAndReplace("\\", "/", TRUE) )
                {
                    url = CHXAvURLRep(url.Protocol(), url.Host(), url.Port(), strNewPath);
                }
            }
        }

        if (!url.Valid())
        {
            // Perhaps invalid because it has unescaped chars
	    url = CHXAvURLFixup::TryEscapeURL(url);
        }
	
        // check for valid URL and supported protocols
        if (url.Valid() &&
	    (stricmp(url.Protocol(), "rtsp") == 0 ||
	     stricmp(url.Protocol(), "http") == 0 ||
	     stricmp(url.Protocol(), "file") == 0))
        {
	    m_url = url;
	    return true;
        }
    }
    return false;
}

bool URLParser::Valid() const
{
    return (m_url.Valid() && (m_url.Protocol().GetLength() > 0));
}

void URLParser::Reset()
{
    m_url = CHXAvURLRep("");
}

const CHXAvURLRep& URLParser::Value() const
{
    return m_url;
}

//////////////////////////////////////////////////////////
//
// the returned playlist is guaranteed to be valid (have at least one item)
//
CHXAvPlaylistPtr CHXAvRAMParser::Parse(const CHXString& filename)
{
    CHXAvPlaylistPtr pList = new (ELeave) CHXAvPlaylist(); // XXXLCM can leave

    CHXAvParseIterator<URLParser> urls(filename);

    for (; urls.More(); urls.Next())
    {
    const URLParser& url = urls.Current();

    if (url.Valid())
        pList->Append(url.Value());
    }

    return pList->Length() > 0 ? pList : CHXAvPlaylistPtr(0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -