示例#1
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);
}
示例#2
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);
}
bool CDVDSubtitleParserVplayer::Open(CDVDStreamInfo &hints)
{
  if (!CDVDSubtitleParserText::Open())
    return false;

  // Vplayer subtitles have 1-second resolution
  m_framerate = DVD_TIME_BASE;

  // Vplayer subtitles don't have StopTime, so we use following subtitle's StartTime
  // for that, unless gap was more than 4 seconds. Then we set subtitle duration
  // for 4 seconds, to not have text hanging around in silent scenes...
  int iDefaultDuration = 4 * (int)m_framerate;

  char line[1024];

  CRegExp reg;
  if (!reg.RegComp("([0-9]+):([0-9]+):([0-9]+):([^|]*?)(\\|([^|]*?))?$"))
    return false;

  CDVDOverlayText* pPrevOverlay = NULL;

  while (m_pStream->ReadLine(line, sizeof(line)))
  {
    if (reg.RegFind(line) > -1)
    {
      std::string hour(reg.GetMatch(1));
      std::string min (reg.GetMatch(2));
      std::string sec (reg.GetMatch(3));
      std::string lines[3];
      lines[0] = reg.GetMatch(4);
      lines[1] = reg.GetMatch(6);
      lines[2] = reg.GetMatch(8);

      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 * (3600*atoi(hour.c_str()) + 60*atoi(min.c_str()) + atoi(sec.c_str()));

      // set StopTime for previous overlay
      if (pPrevOverlay)
      {
        if ( (pOverlay->iPTSStartTime - pPrevOverlay->iPTSStartTime) < iDefaultDuration)
          pPrevOverlay->iPTSStopTime = pOverlay->iPTSStartTime;
        else
          pPrevOverlay->iPTSStopTime = pPrevOverlay->iPTSStartTime + iDefaultDuration;
      }
      pPrevOverlay = pOverlay;
      for (int i = 0; i < 3 && !lines[i].empty(); i++)
          pOverlay->AddElement(new CDVDOverlayText::CElementText(lines[i].c_str()));

      m_collection.Add(pOverlay);
    }

    // set StopTime for the last subtitle
    if (pPrevOverlay)
      pPrevOverlay->iPTSStopTime = pPrevOverlay->iPTSStartTime + iDefaultDuration;
  }

  return true;
}
示例#4
0
void CGUIDialogKeyboard::OnIPAddress()
{
  // find any IP address in the current string if there is any
  // We match to #.#.#.#
  CStdString utf8String;
  g_charsetConverter.wToUTF8(m_strEdit, utf8String);
  CStdString ip;
  CRegExp reg;
  reg.RegComp("[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+");
  int start = reg.RegFind(utf8String.c_str());
  int length = 0;
  if (start > -1)
  {
    length = reg.GetSubLenght(0);
    ip = utf8String.Mid(start, length);
  }
  else
    start = utf8String.size();
  if (CGUIDialogNumeric::ShowAndGetIPAddress(ip, m_strHeading))
  {
    utf8String = utf8String.Left(start) + ip + utf8String.Mid(start + length);
    g_charsetConverter.utf8ToW(utf8String, m_strEdit);
    UpdateLabel();
  }
}
示例#5
0
void CGUIDialogKeyboardGeneric::OnIPAddress()
{
  // find any IP address in the current string if there is any
  // We match to #.#.#.#
  CStdString utf8String;
  g_charsetConverter.wToUTF8(m_strEdit, utf8String);
  CStdString ip;
  CRegExp reg;
  reg.RegComp("[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+");
  int start = reg.RegFind(utf8String.c_str());
  int length = 0;
  if (start > -1)
  {
    length = reg.GetSubLength(0);
    ip = utf8String.Mid(start, length);
  }
  else
    start = utf8String.size();
  if (CGUIDialogNumeric::ShowAndGetIPAddress(ip, g_localizeStrings.Get(14068)))
  {
    utf8String = utf8String.Left(start) + ip + utf8String.Mid(start + length);
    g_charsetConverter.utf8ToW(utf8String, m_strEdit);
    UpdateLabel();
    CGUILabelControl* pEdit = ((CGUILabelControl*)GetControl(CTL_LABEL_EDIT));
    if (pEdit)
      pEdit->SetCursorPos(m_strEdit.size());
  }
}
示例#6
0
TEST(TestRegExp, GetPattern)
{
  CRegExp regex;

  EXPECT_TRUE(regex.RegComp("^(Test)\\s*(.*)\\."));
  EXPECT_STREQ("^(Test)\\s*(.*)\\.", regex.GetPattern().c_str());
}
示例#7
0
void CScraperParser::ConvertJSON(std::string &string)
{
  CRegExp reg;
  reg.RegComp("\\\\u([0-f]{4})");
  while (reg.RegFind(string.c_str()) > -1)
  {
    int pos = reg.GetSubStart(1);
    std::string szReplace(reg.GetMatch(1));

    std::string replace = StringUtils::Format("&#x%s;", szReplace.c_str());
    string.replace(string.begin()+pos-2, string.begin()+pos+4, replace);
  }

  CRegExp reg2;
  reg2.RegComp("\\\\x([0-9]{2})([^\\\\]+;)");
  while (reg2.RegFind(string.c_str()) > -1)
  {
    int pos1 = reg2.GetSubStart(1);
    int pos2 = reg2.GetSubStart(2);
    std::string szHexValue(reg2.GetMatch(1));

    std::string replace = StringUtils::Format("%li", strtol(szHexValue.c_str(), NULL, 16));
    string.replace(string.begin()+pos1-2, string.begin()+pos2+reg2.GetSubLength(2), replace);
  }

  StringUtils::Replace(string, "\\\"","\"");
}
示例#8
0
TEST(TestRegExp, GetCaptureTotal)
{
  CRegExp regex;

  EXPECT_TRUE(regex.RegComp("^(Test)\\s*(.*)\\."));
  EXPECT_EQ(0, regex.RegFind("Test string."));
  EXPECT_EQ(2, regex.GetCaptureTotal());
}
示例#9
0
TEST(TestRegExp, GetSubCount)
{
  CRegExp regex;

  EXPECT_TRUE(regex.RegComp("^(Test)\\s*(.*)\\."));
  EXPECT_EQ(0, regex.RegFind("Test string."));
  EXPECT_EQ(2, regex.GetSubCount());
}
示例#10
0
TEST(TestRegExp, GetReplaceString)
{
  CRegExp regex;

  EXPECT_TRUE(regex.RegComp("^(Test)\\s*(.*)\\."));
  EXPECT_EQ(0, regex.RegFind("Test string."));
  EXPECT_STREQ("string", regex.GetReplaceString("\\2"));
}
示例#11
0
TEST(TestRegExp, GetFindLen)
{
  CRegExp regex;

  EXPECT_TRUE(regex.RegComp("^(Test)\\s*(.*)\\."));
  EXPECT_EQ(0, regex.RegFind("Test string."));
  EXPECT_EQ(12, regex.GetFindLen());
}
示例#12
0
TEST_F(Testlog, Log)
{
    std::string logfile, logstring;
    char buf[100];
    unsigned int bytesread;
    XFILE::CFile file;
    CRegExp regex;

    std::string appName = CCompileInfo::GetAppName();
    StringUtils::ToLower(appName);
    logfile = CSpecialProtocol::TranslatePath("special://temp/") + appName + ".log";
    EXPECT_TRUE(CLog::Init(CSpecialProtocol::TranslatePath("special://temp/").c_str()));
    EXPECT_TRUE(XFILE::CFile::Exists(logfile));

    CLog::Log(LOGDEBUG, "debug log message");
    CLog::Log(LOGINFO, "info log message");
    CLog::Log(LOGNOTICE, "notice log message");
    CLog::Log(LOGWARNING, "warning log message");
    CLog::Log(LOGERROR, "error log message");
    CLog::Log(LOGSEVERE, "severe log message");
    CLog::Log(LOGFATAL, "fatal log message");
    CLog::Log(LOGNONE, "none type log message");
    CLog::Close();

    EXPECT_TRUE(file.Open(logfile));
    while ((bytesread = file.Read(buf, sizeof(buf) - 1)) > 0)
    {
        buf[bytesread] = '\0';
        logstring.append(buf);
    }
    file.Close();
    EXPECT_FALSE(logstring.empty());

    EXPECT_STREQ("\xEF\xBB\xBF", logstring.substr(0, 3).c_str());

    EXPECT_TRUE(regex.RegComp(".*DEBUG: debug log message.*"));
    EXPECT_GE(regex.RegFind(logstring), 0);
    EXPECT_TRUE(regex.RegComp(".*INFO: info log message.*"));
    EXPECT_GE(regex.RegFind(logstring), 0);
    EXPECT_TRUE(regex.RegComp(".*NOTICE: notice log message.*"));
    EXPECT_GE(regex.RegFind(logstring), 0);
    EXPECT_TRUE(regex.RegComp(".*WARNING: warning log message.*"));
    EXPECT_GE(regex.RegFind(logstring), 0);
    EXPECT_TRUE(regex.RegComp(".*ERROR: error log message.*"));
    EXPECT_GE(regex.RegFind(logstring), 0);
    EXPECT_TRUE(regex.RegComp(".*SEVERE: severe log message.*"));
    EXPECT_GE(regex.RegFind(logstring), 0);
    EXPECT_TRUE(regex.RegComp(".*FATAL: fatal log message.*"));
    EXPECT_GE(regex.RegFind(logstring), 0);
    EXPECT_TRUE(regex.RegComp(".*NONE: none type log message.*"));
    EXPECT_GE(regex.RegFind(logstring), 0);

    EXPECT_TRUE(XFILE::CFile::Delete(logfile));
}
示例#13
0
TEST(TestRegExp, GetMatch)
{
  CRegExp regex;

  EXPECT_TRUE(regex.RegComp("^(Test)\\s*(.*)\\."));
  EXPECT_EQ(0, regex.RegFind("Test string."));
  EXPECT_STREQ("Test string.", regex.GetMatch(0).c_str());
  EXPECT_STREQ("Test", regex.GetMatch(1).c_str());
  EXPECT_STREQ("string", regex.GetMatch(2).c_str());
}
示例#14
0
TEST(TestRegExp, GetSubStart)
{
  CRegExp regex;

  EXPECT_TRUE(regex.RegComp("^(Test)\\s*(.*)\\."));
  EXPECT_EQ(0, regex.RegFind("Test string."));
  EXPECT_EQ(0, regex.GetSubStart(0));
  EXPECT_EQ(0, regex.GetSubStart(1));
  EXPECT_EQ(5, regex.GetSubStart(2));
}
示例#15
0
TEST(TestRegExp, GetNamedSubPattern)
{
  CRegExp regex;
  std::string match;

  EXPECT_TRUE(regex.RegComp("^(?<first>Test)\\s*(?<second>.*)\\."));
  EXPECT_EQ(0, regex.RegFind("Test string."));
  EXPECT_TRUE(regex.GetNamedSubPattern("first", match));
  EXPECT_STREQ("Test", match.c_str());
  EXPECT_TRUE(regex.GetNamedSubPattern("second", match));
  EXPECT_STREQ("string", match.c_str());
}
示例#16
0
void CAndroidStorageProvider::GetRemovableDrives(VECSOURCES &removableDrives)
{
    // mounted usb disks
    std::vector<CStdString> result;
    CRegExp reMount;
    reMount.RegComp("^(.+?)\\s+(.+?)\\s+(.+?)\\s");
    char line[1024];

    FILE* pipe = fopen("/proc/mounts", "r");

    if (pipe)
    {
        while (fgets(line, sizeof(line) - 1, pipe))
        {
            if (reMount.RegFind(line) != -1)
            {
                bool accepted = false;
                std::string mountStr = reMount.GetReplaceString("\\2");
                std::string fsStr    = reMount.GetReplaceString("\\3");
                const char* mount = mountStr.c_str();
                const char* fs    = fsStr.c_str();

                // Here we choose which filesystems are approved
                if (strcmp(fs, "fuseblk") == 0 || strcmp(fs, "vfat") == 0
                        || strcmp(fs, "ext2") == 0 || strcmp(fs, "ext3") == 0 || strcmp(fs, "ext4") == 0
                        || strcmp(fs, "reiserfs") == 0 || strcmp(fs, "xfs") == 0
                        || strcmp(fs, "ntfs-3g") == 0 || strcmp(fs, "iso9660") == 0
                        || strcmp(fs, "exfat") == 0
                        || strcmp(fs, "fusefs") == 0 || strcmp(fs, "hfs") == 0)
                    accepted = true;

                // Ignore everything but usb
                if (!StringUtils::StartsWith(mountStr, "/mnt/usb"))
                    accepted = false;

                if(accepted)
                    result.push_back(mount);
            }
        }
        fclose(pipe);
    } else
        CLog::Log(LOGERROR, "Cannot read mount points");

    for (unsigned int i = 0; i < result.size(); i++)
    {
        CMediaSource share;
        share.strPath = unescape(result[i]);
        share.strName = URIUtils::GetFileName(share.strPath);
        share.m_ignore = true;
        removableDrives.push_back(share);
    }
}
bool CDVDSubtitleParserSami::Open(CDVDStreamInfo &hints)
{
  if (!m_pStream->Open(m_strFileName))
    return false;

  char line[1024];
  char text[1024];

  CRegExp reg;
  if (!reg.RegComp("<SYNC START=([0-9]+)>"))
    assert(0);

  bool reuse=false;
  while (reuse || m_pStream->ReadLine(line, sizeof(line)))
  {
    if (reg.RegFind(line) > -1)
    {
      char* startFrame = reg.GetReplaceString("\\1");
      m_pStream->ReadLine(text,sizeof(text));
      m_pStream->ReadLine(line,sizeof(line));
      if (reg.RegFind(line) > -1)
      {
        char* endFrame   = reg.GetReplaceString("\\1");
      
        CDVDOverlayText* pOverlay = new CDVDOverlayText();
        pOverlay->Acquire(); // increase ref count with one so that we can hold a handle to this overlay

        pOverlay->iPTSStartTime = atoi(startFrame)*DVD_TIME_BASE/1000; 
        pOverlay->iPTSStopTime  = atoi(endFrame)*DVD_TIME_BASE/1000;

        CStdStringW strUTF16;
        CStdStringA strUTF8;
        g_charsetConverter.subtitleCharsetToW(text, strUTF16);
        g_charsetConverter.wToUTF8(strUTF16, strUTF8);
        if (strUTF8.IsEmpty())
          continue;
        // add a new text element to our container
        pOverlay->AddElement(new CDVDOverlayText::CElementText(strUTF8.c_str()));
        reuse = true;
        free(endFrame);
      
        m_collection.Add(pOverlay);
      }
      free(startFrame);
    }
    else
      reuse = false;
  }

  return true;
}
示例#18
0
TEST_F(Testlog, MemDump)
{
    std::string logfile, logstring;
    char buf[100];
    unsigned int bytesread;
    XFILE::CFile file;
    CRegExp regex;
    char refdata[] = "0123456789abcdefghijklmnopqrstuvwxyz";

    std::string appName = CCompileInfo::GetAppName();
    StringUtils::ToLower(appName);
    logfile = CSpecialProtocol::TranslatePath("special://temp/") + appName + ".log";
    EXPECT_TRUE(CLog::Init(CSpecialProtocol::TranslatePath("special://temp/").c_str()));
    EXPECT_TRUE(XFILE::CFile::Exists(logfile));

    CLog::MemDump(refdata, sizeof(refdata));
    CLog::Close();

    EXPECT_TRUE(file.Open(logfile));
    while ((bytesread = file.Read(buf, sizeof(buf) - 1)) > 0)
    {
        buf[bytesread] = '\0';
        logstring.append(buf);
    }
    file.Close();
    EXPECT_FALSE(logstring.empty());

    EXPECT_STREQ("\xEF\xBB\xBF", logstring.substr(0, 3).c_str());

    EXPECT_TRUE(regex.RegComp(".*DEBUG: MEM_DUMP: Dumping from.*"));
    EXPECT_GE(regex.RegFind(logstring), 0);
    EXPECT_TRUE(regex.RegComp(".*DEBUG: MEM_DUMP: 0000  30 31 32 33.*"));
    EXPECT_GE(regex.RegFind(logstring), 0);
    EXPECT_TRUE(regex.RegComp(".*73 74 75 76  ghijklmnopqrstuv.*"));
    EXPECT_GE(regex.RegFind(logstring), 0);

    EXPECT_TRUE(XFILE::CFile::Delete(logfile));
}
示例#19
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);
}
示例#20
0
TEST_F(TestRegExpLog, DumpOvector)
{
  CRegExp regex;
  CStdString logfile, logstring;
  char buf[100];
  unsigned int bytesread;
  XFILE::CFile file;

  std::string appName = CCompileInfo::GetAppName();
  StringUtils::ToLower(appName);
  logfile = CSpecialProtocol::TranslatePath("special://temp/") + appName + ".log";
  EXPECT_TRUE(CLog::Init(CSpecialProtocol::TranslatePath("special://temp/").c_str()));
  EXPECT_TRUE(XFILE::CFile::Exists(logfile));

  EXPECT_TRUE(regex.RegComp("^(?<first>Test)\\s*(?<second>.*)\\."));
  EXPECT_EQ(0, regex.RegFind("Test string."));
  regex.DumpOvector(LOGDEBUG);
  CLog::Close();

  EXPECT_TRUE(file.Open(logfile));
  while ((bytesread = file.Read(buf, sizeof(buf) - 1)) > 0)
  {
    buf[bytesread] = '\0';
    logstring.append(buf);
  }
  file.Close();
  EXPECT_FALSE(logstring.empty());

  EXPECT_STREQ("\xEF\xBB\xBF", logstring.substr(0, 3).c_str());

  EXPECT_TRUE(regex.RegComp(".*DEBUG: regexp ovector=\\{\\[0,12\\],\\[0,4\\],"
                            "\\[5,11\\]\\}.*"));
  EXPECT_GE(regex.RegFind(logstring), 0);

  EXPECT_TRUE(XFILE::CFile::Delete(logfile));
}
示例#21
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);
}
示例#22
0
bool aml_support_hevc_4k2k()
{
  static int has_hevc_4k2k = -1;

  if (has_hevc_4k2k == -1)
  {
    CRegExp regexp;
    regexp.RegComp("hevc:.*4k");
    std::string valstr;
    if (SysfsUtils::GetString("/sys/class/amstream/vcodec_profile", valstr) != 0)
      has_hevc_4k2k = 0;
    else
      has_hevc_4k2k = (regexp.RegFind(valstr) >= 0) ? 1 : 0;
  }
  return (has_hevc_4k2k == 1);
}
示例#23
0
TEST(TestZipManager, PathTraversal)
{
  CRegExp pathTraversal;
  pathTraversal.RegComp(PATH_TRAVERSAL);

  ASSERT_TRUE(pathTraversal.RegFind("..") >= 0);
  ASSERT_TRUE(pathTraversal.RegFind("../test.txt") >= 0);
  ASSERT_TRUE(pathTraversal.RegFind("..\\test.txt") >= 0);
  ASSERT_TRUE(pathTraversal.RegFind("test/../test.txt") >= 0);
  ASSERT_TRUE(pathTraversal.RegFind("test\\../test.txt") >= 0);
  ASSERT_TRUE(pathTraversal.RegFind("test\\..\\test.txt") >= 0);

  ASSERT_FALSE(pathTraversal.RegFind("...") >= 0);
  ASSERT_FALSE(pathTraversal.RegFind("..test.txt") >= 0);
  ASSERT_FALSE(pathTraversal.RegFind("test.txt..") >= 0);
  ASSERT_FALSE(pathTraversal.RegFind("test..test.txt") >= 0);
}
示例#24
0
void CCedtApp::OnSearchFindInFiles() 
{
	// static dialog box to remember last settings...
	static CFindInFilesDialog dlg;

	CMainFrame * pFrame = (CMainFrame *)AfxGetMainWnd(); ASSERT( pFrame );
	if( ! pFrame->CanUseOutputWindow() ) {
		AfxMessageBox(IDS_ERR_OUTPUT_WINDOW_OCCUPIED, MB_OK | MB_ICONSTOP); return;
	}

	CCedtView * pView = (CCedtView *)pFrame->MDIGetActiveView();
	CCedtDoc * pDoc = (pView) ? (CCedtDoc *)pView->GetDocument() : NULL;

	if( pDoc && pView ) {
		dlg.m_szFindString = pView->GetCurrentWord();
		if( pView->IsSelected() && ! pView->GetSelectedLineCount() ) dlg.m_szFindString = pView->GetSelectedString();

		if( ! dlg.m_szFolder.GetLength() ) {
			CString szPathName = pDoc->GetPathName();
			if( szPathName.GetLength() ) dlg.m_szFolder = GetFileDirectory( szPathName );
		}
	} else {
		if( ! dlg.m_szFolder.GetLength() ) {
			TCHAR szTemp[MAX_PATH]; GetCurrentDirectory(MAX_PATH, szTemp);
			dlg.m_szFolder = szTemp;
		}
	}

	if( dlg.DoModal() != IDOK ) return;

	CString szFindString = dlg.m_szFindString;
	CString szFileType = dlg.m_szFileType;
	CString szFolder = dlg.m_szFolder;

	BOOL bLookSubfolders = dlg.m_bLookSubfolders;
	UINT nOptions = COMPOSE_SEARCH_OPTION( dlg.m_bWholeWord, dlg.m_bMatchCase, dlg.m_bRegularExpression);

	CRegExp clsTestRegExp; // compile regular expression for test
	if( HAS_REG_EXP(nOptions) && ! clsTestRegExp.RegComp(szFindString) ) {
		CString szMessage; szMessage.Format(IDS_ERR_REG_COMP_FAILED, szFindString);
		AfxMessageBox(szMessage); return; // test failed
	}

	DoFindInFiles(szFindString, szFileType, szFolder, bLookSubfolders, nOptions); 
}
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;
}
示例#26
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;
}
示例#27
0
const std::vector<std::string> CTagLoaderTagLib::SplitMBID(const std::vector<std::string> &values)
{
  if (values.empty() || values.size() > 1)
    return values;

  // Picard, and other taggers use a heap of different separators.  We use a regexp to detect
  // MBIDs to make sure we hit them all...
  std::vector<std::string> ret;
  std::string value = values[0];
  StringUtils::ToLower(value);
  CRegExp reg;
  if (reg.RegComp("([[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12})"))
  {
    int pos = -1;
    while ((pos = reg.RegFind(value, pos+1)) > -1)
      ret.push_back(reg.GetMatch(1));
  }
  return ret;
}
示例#28
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;
}
void CGUIDialogKeyboardGeneric::OnIPAddress()
{
    // find any IP address in the current string if there is any
    // We match to #.#.#.#
    std::string text = GetText();
    std::string ip;
    CRegExp reg;
    reg.RegComp("[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+");
    int start = reg.RegFind(text.c_str());
    int length = 0;
    if (start > -1)
    {
        length = reg.GetSubLength(0);
        ip = text.substr(start, length);
    }
    else
        start = text.size();
    if (CGUIDialogNumeric::ShowAndGetIPAddress(ip, g_localizeStrings.Get(14068)))
        SetEditText(text.substr(0, start) + ip.c_str() + text.substr(start + length));
}
bool CGUIDialogFirstTimeUseConfNetwork::ValidateFields()
{
  CRegExp reg;
  reg.RegComp(IP_REGEXP);
  CStdString editStr = "";

  // check IpAddress value
  editStr = ((CGUIEditControl*)GetControl(CONTROL_IP_ADDRESS_EDIT))->GetLabel2();
  if (reg.RegFind(editStr.c_str()) == -1)
  {
    CLog::Log(LOGERROR,"CGUIDialogFirstTimeUseConfNetwork::ValidateFields - [ipaddress=%s] is NOT valid (initbox)",editStr.c_str());
    return false;
  }

  // check IpAddress value
  editStr = ((CGUIEditControl*)GetControl(CONTROL_NETMASK_EDIT))->GetLabel2();
  if (reg.RegFind(editStr.c_str()) == -1)
  {
    CLog::Log(LOGERROR,"CGUIDialogFirstTimeUseConfNetwork::ValidateFields - [netmask=%s] is NOT valid (initbox)",editStr.c_str());
    return false;
  }

  // check IpAddress value
  editStr = ((CGUIEditControl*)GetControl(CONTROL_GATEWAY_EDIT))->GetLabel2();
  if (reg.RegFind(editStr.c_str()) == -1)
  {
    CLog::Log(LOGERROR,"CGUIDialogFirstTimeUseConfNetwork::ValidateFields - [gateway=%s] is NOT valid (initbox)",editStr.c_str());
    return false;
  }

  // check IpAddress value
  editStr = ((CGUIEditControl*)GetControl(CONTROL_DNS_EDIT))->GetLabel2();
  if (reg.RegFind(editStr.c_str()) == -1)
  {
    CLog::Log(LOGERROR,"CGUIDialogFirstTimeUseConfNetwork::ValidateFields - [dns=%s] is NOT valid (initbox)",editStr.c_str());
    return false;
  }

  return true;
}