網頁

2016年8月5日 星期五

[gitlab] how to merge request by gitlab

主題:
How to merge request by gitlab

步驟:
1. fork project on gitlab UI, and you will get a git respository location like: git@git.xxxx:[yourname]/[projectname].git
    gitlab -> select project -> fork
    
2. add respository
      git remote add upstream git@git.xxxx:[yourname]/[projectname].git

3. check if the repository is added
      git remote -v

4. fetch the repository
     git fetch upstream

5. push your commit to the repository instead of 'origin' repository
    git push upstream master

6. create merge request on gitlab UI
    gitlab -> select [merge requests] -> click [New merge request] ....

7. wait project owner to merge the code

8. delete the repository on gitlab UI

2016年5月11日 星期三

use c++ regex parse string enclosed in double quote

主題:

use c++ regex parse string enclosed in double quote

難處:

考慮 escaped quote


範例:

如果是 std::string s = "\"\\\"aaa\"\"bbb\"";   要 parse 成  \"aaa & bbb
以下我直接貼 code, 後面註解是想要 parse 的結果

std::string s = "\"\\\\\"aaa\"\"bbb\"";       // \\"aaa & bbb
std::string s = "\"aa\\\"a\" \"bbb\"";        // aa\"a  & bbb
std::string s = "\"aa\\\\\"a\" \"bbb\"";      // aa\\"a & bbb
std::string s = "\"\"\"aaa\"\t \"bbb\"";     // empty & aaa & bbb



怎麼寫:

std::regex e ("\"((([^\\\\]*\\\\.)|([^\"]*))*)\"");
std::smatch sm;
std::string line = s;
while (std::regex_search (line, sm, e)) {
    std::cout << "range with " << sm.size() << " matches\n";
    std::cout << "the matches were: ";
    for (unsigned i=0; i<sm.size(); ++i) {
        std::cout << "[" << sm[i] << "] ";
    }
    line = sm.suffix().str();
    std::cout << std::endl << "line: " << line;
    std::cout << std::endl;
}

// 裡面印出的 sm[1] 就是我們想要的結果

參考: 

http://stackoverflow.com/questions/21658860/how-to-use-regex-c
http://www.cplusplus.com/reference/regex/match_results/suffix/
http://stackoverflow.com/questions/6863518/regex-match-one-of-two-words
http://stackoverflow.com/questions/249791/regex-for-quoted-string-with-escaping-quotes (Guy BedFord 的寫法再改良)