直播短视频源码,实现文本替换

2021-01-04 10:58:33 浏览数 (1)

直播短视频源码,实现文本替换相关的代码

代码语言:javascript复制
#include <stdio.h>
#include <string>
#include <regex>
#include <fstream>
#include <iostream>
#include <set>
using namespace std;
//    ? 与 {0,1}:0个或1个前面的内容 或 前面的内容是可选的
//    * 与 {0,} : 0 个或多个前面的内容
//      与 {1,}: 1 个或多个前面的内容
void mtRW(string basePath,string dirName,string strReplace){
    string path = basePath dirName ".vmoptions";
    string pathBak=basePath dirName ".vmoptions.bak";
    string pathRe = basePath dirName ".vmoptions-Re";
    string cmd1="gedit " string(path);
    string cmd2="gedit " string(pathBak);
    regex patternTempRe("^-javaagent:/home/jl73/.jetbrains/jetbrains-agent-v3.2.0.0f1f.69e=(.*)");
    string temp;
    string temp2="";
    set<string> chs;
    set<string>::iterator it;
//    regex patternSet("[^A-Za-z0-9 \t]");
    regex patternSet("[^A-Za-z0-9 \t\\]");
    smatch resultTempRe,resultSet;
    string strTempRe;
    ifstream rf(path);
    if(!rf){
        cout<<"read xxx"<<endl;
    }
    ofstream wfBak(pathBak);
    if(!wfBak){
        cout << "bak xxx" << endl;
    }
    while(getline(rf,temp)){
        wfBak<<temp<<endl;
        if(regex_match(temp,resultTempRe,patternTempRe)) {
            strTempRe=string(resultTempRe[1]);
            string::const_iterator iterStart = strTempRe.begin();
            string::const_iterator iterEnd = strTempRe.end();
            string tmp;
            while (regex_search(iterStart, iterEnd, resultSet, patternSet)) {
                tmp = resultSet[0];
                chs.insert((string)tmp);
                iterStart = resultSet[0].second;    //更新搜索起始位置,搜索剩下的字符串
            }
//            chs.erase("\");
            strTempRe = regex_replace(strTempRe, regex("\\"), "\\");
            for (auto ch:chs) {
                strTempRe = regex_replace(strTempRe, regex("\"   ch), "\"   ch);
            }
            temp2=temp2 regex_replace(temp,regex(strTempRe),strReplace) "n";
        }
        else{
            temp2=temp2 temp 'n';
        }
    }
    rf.close();
    wfBak.close();
//    ofstream wf(path);
    ofstream wf(pathRe);
    if(!wf){
        cout<<"write xxx"<<endl;
    }
    wf<<temp2;
    wf.close();
//    system(cmd1.c_str());
//    system(cmd2.c_str());
    cout << dirName <<"treplace done"<< endl;
}
int main(int argc,const char *argv[]){
//    if(argc!=2){
//        perror("argc=2");
//        exit(1);
//    }
//    string basePath="/home/jl73/.config/JetBrains/";
    string basePath="/home/jl73/7-tmp/";
    string dirNames[]={"CLion2020.2/clion","GoLand2020.2/goland","IntelliJIdea2020.2/idea","PyCharm2020.2/pycharm"};
//    string strReplace="12`!@#%&-_=:|}].;"'<>/\\\\<>. \$^*() {}[]|?`, /!@#%&-_=:;"'<>.";
    string strReplace;
    ifstream rf(basePath "str");
    if(!rf){
        cout<<"read xxx"<<endl;
    }
    getline(rf,strReplace);
//    cout << strReplace << endl;
    for (auto dirName  :dirNames ) {
        mtRW(basePath,dirName,strReplace);
//        mtRW(basePath,dirName,argv[1]);
    }
    return 0;
}

以上就是直播短视频源码,实现文本替换相关的代码, 更多内容欢迎关注之后的文章

0 人点赞