Esempio n. 1
0
void CLabelFormatter::AssembleMask(unsigned int label, const CStdString& mask)
{
  assert(label < 2);
  m_staticContent[label].clear();
  m_dynamicContent[label].clear();

  // we want to match [<prefix>%A<postfix]
  // but allow %%, %[, %] to be in the prefix and postfix.  Anything before the first [
  // could be a mask that's not surrounded with [], so pass to SplitMask.
  CRegExp reg;
  reg.RegComp("(^|[^%])\\[(([^%]|%%|%\\]|%\\[)*)%([" MASK_CHARS "])(([^%]|%%|%\\]|%\\[)*)\\]");
  CStdString work(mask);
  int findStart = -1;
  while ((findStart = reg.RegFind(work.c_str())) >= 0)
  { // we've found a match for a pre/postfixed string
    // send anything
    char *s1 = reg.GetReplaceString("\\1");
    char *s2 = reg.GetReplaceString("\\2");
    char *s4 = reg.GetReplaceString("\\4");
    char *s5 = reg.GetReplaceString("\\5");
    SplitMask(label, work.Left(findStart) + s1);
    m_dynamicContent[label].push_back(CMaskString(s2, *s4, s5));
    free(s1);
    free(s2);
    free(s4);
    free(s5);
    work = work.Mid(findStart + reg.GetFindLen());
  }
  SplitMask(label, work);
  assert(m_staticContent[label].size() == m_dynamicContent[label].size() + 1);
}
Esempio n. 2
0
void CLabelFormatter::AssembleMask(unsigned int label, const std::string& mask)
{
  assert(label < 2);
  m_staticContent[label].clear();
  m_dynamicContent[label].clear();

  // we want to match [<prefix>%A<postfix]
  // but allow %%, %[, %] to be in the prefix and postfix.  Anything before the first [
  // could be a mask that's not surrounded with [], so pass to SplitMask.
  CRegExp reg;
  reg.RegComp("(^|[^%])\\[(([^%]|%%|%\\]|%\\[)*)%([" MASK_CHARS "])(([^%]|%%|%\\]|%\\[)*)\\]");
  std::string work(mask);
  int findStart = -1;
  while ((findStart = reg.RegFind(work.c_str())) >= 0)
  { // we've found a match for a pre/postfixed string
    // send anything
    SplitMask(label, work.substr(0, findStart) + reg.GetMatch(1));
    m_dynamicContent[label].push_back(CMaskString(
            reg.GetMatch(2),
            reg.GetMatch(4)[0],
            reg.GetMatch(5)));
    work = work.substr(findStart + reg.GetFindLen());
  }
  SplitMask(label, work);
  assert(m_staticContent[label].size() == m_dynamicContent[label].size() + 1);
}
Esempio n. 3
0
TEST(TestRegExp, GetFindLen)
{
  CRegExp regex;

  EXPECT_TRUE(regex.RegComp("^(Test)\\s*(.*)\\."));
  EXPECT_EQ(0, regex.RegFind("Test string."));
  EXPECT_EQ(12, regex.GetFindLen());
}
Esempio n. 4
0
void CLabelFormatter::SplitMask(unsigned int label, const CStdString &mask)
{
  assert(label < 2);
  CRegExp reg;
  reg.RegComp("%([" MASK_CHARS "])");
  CStdString work(mask);
  int findStart = -1;
  while ((findStart = reg.RegFind(work.c_str())) >= 0)
  { // we've found a match
    m_staticContent[label].push_back(work.Left(findStart));
    m_dynamicContent[label].push_back(CMaskString("", *reg.GetReplaceString("\\1"), ""));
    work = work.Mid(findStart + reg.GetFindLen());
  }
  m_staticContent[label].push_back(work);
}
Esempio n. 5
0
void CLabelFormatter::SplitMask(unsigned int label, const std::string &mask)
{
  assert(label < 2);
  CRegExp reg;
  reg.RegComp("%([" MASK_CHARS "])");
  std::string work(mask);
  int findStart = -1;
  while ((findStart = reg.RegFind(work.c_str())) >= 0)
  { // we've found a match
    m_staticContent[label].push_back(work.substr(0, findStart));
    m_dynamicContent[label].push_back(CMaskString("", 
          reg.GetMatch(1)[0], ""));
    work = work.substr(findStart + reg.GetFindLen());
  }
  m_staticContent[label].push_back(work);
}
bool CDVDSubtitleParserMicroDVD::Open(CDVDStreamInfo &hints)
{
  if (!CDVDSubtitleParserText::Open())
    return false;

  CLog::Log(LOGDEBUG, "%s - framerate %d:%d", __FUNCTION__, hints.fpsrate, hints.fpsscale);
  if (hints.fpsscale > 0 && hints.fpsrate > 0)
  {
    m_framerate = (double)hints.fpsscale / (double)hints.fpsrate;
    m_framerate *= DVD_TIME_BASE;
  }
  else
    m_framerate = DVD_TIME_BASE / 25.0;

  char line[1024];

  CRegExp reg;
  if (!reg.RegComp("\\{([0-9]+)\\}\\{([0-9]+)\\}"))
    return false;
  CDVDSubtitleTagMicroDVD TagConv;

  while (m_pStream->ReadLine(line, sizeof(line)))
  {
    if ((strlen(line) > 0) && (line[strlen(line) - 1] == '\r'))
      line[strlen(line) - 1] = 0;

    int pos = reg.RegFind(line);
    if (pos > -1)
    {
      const char* text = line + pos + reg.GetFindLen();
      std::string startFrame = reg.GetReplaceString("\\1");
      std::string endFrame   = reg.GetReplaceString("\\2");
      CDVDOverlayText* pOverlay = new CDVDOverlayText();
      pOverlay->Acquire(); // increase ref count with one so that we can hold a handle to this overlay

      pOverlay->iPTSStartTime = m_framerate * atoi(startFrame.c_str());
      pOverlay->iPTSStopTime  = m_framerate * atoi(endFrame.c_str());

      TagConv.ConvertLine(pOverlay, text, strlen(text));
      m_collection.Add(pOverlay);
    }
  }

  return true;
}
Esempio n. 7
0
std::string FilterMessage(std::string message)
{
  std::string filteredMessage = message;
  CRegExp reg;
  for (int i = 0; i < sizeof(filter) / 100; i++)
  {
    reg.RegComp(filter[i]);
    int findStart = reg.RegFind(message.c_str());
    while (findStart >= 0)
    {
      filteredMessage = message.substr(0, findStart);
      filteredMessage.append(message.substr(findStart + reg.GetFindLen(), message.length()));
      message = filteredMessage;
      findStart = reg.RegFind(message.c_str());
    }
  }
  return filteredMessage;
}
Esempio n. 8
0
bool CDVDSubtitleParserMPL2::Open(CDVDStreamInfo &hints)
{
  if (!CDVDSubtitleParserText::Open())
    return false;

  // MPL2 is time-based, with 0.1s accuracy
  m_framerate = DVD_TIME_BASE / 10.0;

  char line[1024];

  CRegExp reg;
  if (!reg.RegComp("\\[([0-9]+)\\]\\[([0-9]+)\\]"))
    return false;
  CDVDSubtitleTagMicroDVD TagConv;

  while (m_pStream->ReadLine(line, sizeof(line)))
  {
    if ((strlen(line) > 0) && (line[strlen(line) - 1] == '\r'))
      line[strlen(line) - 1] = 0;

    int pos = reg.RegFind(line);
    if (pos > -1)
    {
      const char* text = line + pos + reg.GetFindLen();
      char* startFrame = reg.GetReplaceString("\\1");
      char* endFrame   = reg.GetReplaceString("\\2");
      CDVDOverlayText* pOverlay = new CDVDOverlayText();
      pOverlay->Acquire(); // increase ref count with one so that we can hold a handle to this overlay

      pOverlay->iPTSStartTime = m_framerate * atoi(startFrame);
      pOverlay->iPTSStopTime  = m_framerate * atoi(endFrame);

      TagConv.ConvertLine(pOverlay, text, strlen(text));

      free(startFrame);
      free(endFrame);

      m_collection.Add(pOverlay);
    }
  }

  return true;
}