Skip to content

Commit

Permalink
Change to std::string in COMXSubtitleTagSami (from XBMC)
Browse files Browse the repository at this point in the history
  • Loading branch information
torarin committed Jun 13, 2012
1 parent b0980ac commit 11d4ed9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
43 changes: 23 additions & 20 deletions OMXSubtitleTagSami.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "OMXOverlayText.h"
#include "utils/RegExp.h"

#include <boost/algorithm/string.hpp>

COMXSubtitleTagSami::~COMXSubtitleTagSami()
{
delete m_tags;
Expand All @@ -46,17 +48,18 @@ bool COMXSubtitleTagSami::Init()

void COMXSubtitleTagSami::ConvertLine(COMXOverlayText* pOverlay, const char* line, int len, const char* lang)
{
CStdStringA strUTF8;
std::string strUTF8;
strUTF8.assign(line, len);
strUTF8.Trim();

boost::algorithm::trim(strUTF8);

int pos = 0;
int del_start = 0;
while ((pos=m_tags->RegFind(strUTF8.c_str(), pos)) >= 0)
{
// Parse Tags
CStdString fullTag = m_tags->GetMatch(0);
fullTag.ToLower();
std::string fullTag = m_tags->GetMatch(0);
boost::algorithm::to_lower(fullTag);
strUTF8.erase(pos, fullTag.length());
if (fullTag == "<b>" || fullTag == "{\\b1}")
{
Expand Down Expand Up @@ -88,12 +91,12 @@ void COMXSubtitleTagSami::ConvertLine(COMXOverlayText* pOverlay, const char* lin
strUTF8.insert(pos, "[/COLOR]");
pos += 8;
}
else if (fullTag.Left(5) == "{\\c&h" || fullTag.Left(6) == "{\\1c&h")
else if (fullTag.substr(0,5) == "{\\c&h" || fullTag.substr(0,6) == "{\\1c&h")
{
m_flag[FLAG_COLOR] = true;
CStdString tempColorTag = "[COLOR FF";
CStdString tagOptionValue;
if (fullTag.Left(5) == "{\\c&h")
std::string tempColorTag = "[COLOR FF";
std::string tagOptionValue;
if (fullTag.substr(0, 5) == "{\\c&h")
tagOptionValue = fullTag.substr(5,6);
else
tagOptionValue = fullTag.substr(6,6);
Expand All @@ -104,18 +107,18 @@ void COMXSubtitleTagSami::ConvertLine(COMXOverlayText* pOverlay, const char* lin
strUTF8.insert(pos, tempColorTag);
pos += tempColorTag.length();
}
else if (fullTag.Left(5) == "<font")
else if (fullTag.substr(0,5) == "<font")
{
int pos2 = 5;
while ((pos2 = m_tagOptions->RegFind(fullTag.c_str(), pos2)) >= 0)
{
CStdString tagOptionName = m_tagOptions->GetMatch(1);
CStdString tagOptionValue = m_tagOptions->GetMatch(2);
std::string tagOptionName = m_tagOptions->GetMatch(1);
std::string tagOptionValue = m_tagOptions->GetMatch(2);
pos2 += tagOptionName.length() + tagOptionValue.length();
if (tagOptionName == "color")
{
m_flag[FLAG_COLOR] = true;
CStdString tempColorTag = "[COLOR ";
std::string tempColorTag = "[COLOR ";
if (tagOptionValue[0] == '#')
{
tagOptionValue.erase(0, 1);
Expand Down Expand Up @@ -144,13 +147,13 @@ void COMXSubtitleTagSami::ConvertLine(COMXOverlayText* pOverlay, const char* lin
}
}
}
else if (lang && (fullTag.Left(3) == "<p "))
else if (lang && (fullTag.substr(0,3) == "<p "))
{
int pos2 = 3;
while ((pos2 = m_tagOptions->RegFind(fullTag.c_str(), pos2)) >= 0)
{
CStdString tagOptionName = m_tagOptions->GetMatch(1);
CStdString tagOptionValue = m_tagOptions->GetMatch(2);
std::string tagOptionName = m_tagOptions->GetMatch(1);
std::string tagOptionValue = m_tagOptions->GetMatch(2);
pos2 += tagOptionName.length() + tagOptionValue.length();
if (tagOptionName == "class")
{
Expand All @@ -159,7 +162,7 @@ void COMXSubtitleTagSami::ConvertLine(COMXOverlayText* pOverlay, const char* lin
strUTF8.erase(del_start, pos - del_start);
pos = del_start;
}
if (!tagOptionValue.Compare(lang))
if (tagOptionValue != lang)
{
m_flag[FLAG_LANGUAGE] = false;
}
Expand All @@ -178,21 +181,21 @@ void COMXSubtitleTagSami::ConvertLine(COMXOverlayText* pOverlay, const char* lin
pos = del_start;
m_flag[FLAG_LANGUAGE] = false;
}
else if (fullTag == "<br>" && !strUTF8.IsEmpty())
else if (fullTag == "<br>" && !strUTF8.empty())
{
strUTF8.Insert(pos, "\n");
strUTF8.insert(pos, "\n");
pos += 1;
}
}

if(m_flag[FLAG_LANGUAGE])
strUTF8.erase(del_start);

if (strUTF8.IsEmpty())
if (strUTF8.empty())
return;

if( strUTF8[strUTF8.size()-1] == '\n' )
strUTF8.Delete(strUTF8.size()-1);
strUTF8.erase(strUTF8.size()-1, 1);

// add a new text element to our container
pOverlay->AddElement(new COMXOverlayText::CElementText(strUTF8.c_str()));
Expand Down
4 changes: 3 additions & 1 deletion OMXSubtitleTagSami.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
*
*/
#include <stdio.h>
#include "utils/StdString.h"

#include <string>
#include <vector>

#define FLAG_BOLD 0
#define FLAG_ITALIC 1
Expand Down

0 comments on commit 11d4ed9

Please sign in to comment.