eGospodarka.pl
eGospodarka.pl poleca

eGospodarka.plGrupypl.comp.programmingproblem z wyrażeniem regularnym w C++ › Re: problem z wyrażeniem regularnym w C++
  • Path: news-archive.icm.edu.pl!news.icm.edu.pl!wsisiz.edu.pl!.POSTED.user-5-173-155-76
    .play-internet.pl!not-for-mail
    From: RM <r...@w...pl>
    Newsgroups: pl.comp.programming
    Subject: Re: problem z wyrażeniem regularnym w C++
    Date: Tue, 7 Apr 2020 19:07:37 +0200
    Organization: http://www.wit.edu.pl
    Message-ID: <r6ic0t$2mpot$1@portraits.wsisiz.edu.pl>
    References: <r6fk76$209a1$1@portraits.wsisiz.edu.pl>
    Mime-Version: 1.0
    Content-Type: text/plain; charset=utf-8; format=flowed
    Content-Transfer-Encoding: 8bit
    Injection-Date: Tue, 7 Apr 2020 17:07:41 -0000 (UTC)
    Injection-Info: portraits.wsisiz.edu.pl;
    posting-host="user-5-173-155-76.play-internet.pl:5.173.155.76";
    logging-data="2844445"; mail-complaints-to="a...@w...edu.pl"
    User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
    Thunderbird/68.2.1
    In-Reply-To: <r6fk76$209a1$1@portraits.wsisiz.edu.pl>
    Content-Language: en-US
    Xref: news-archive.icm.edu.pl pl.comp.programming:214814
    [ ukryj nagłówki ]

    Potrzebuję jeszcze pomocy przy przetumaczeniu kawałka kodu z PHP na C++,
    bo dokumentacji do C++owego sub_match nie rozumiem. Problem jest dla
    mnie za trudny.

    W PHP mam:

    preg_match_all($r, $line, $matches, PREG_OFFSET_CAPTURE))
    ...
    $match = $matches[$indexes[$what][$k]];
    $delta_str = 0;
    foreach ($match as $m) {
    if ($what == 'f' && $k == 1) { // 2nd regexp for functions
    // check if a method call:
    $before = substr($line, $m[1] - 2, 2);
    if ($before == '->' || $before == '::') continue; // don't obfuscate now
    }
    if ($what == 'f') { // case insensitive
    $n = array_search(strtoupper($m[0]), $from[$what]);
    } elseif ($what == 'm') { // case insensitive
    if (in_array(strtoupper($m[0]), $from['a'])) { // action
    $n = FALSE;
    } else {
    $n = array_search(strtoupper($m[0]), $from[$what]);
    }
    } else {
    $n = array_search($m[0], $from[$what]);
    }
    if ($n !== FALSE) {
    $line = substr_replace($line, '_' . $to[$what][$n], $m[1] +
    $delta_str, strlen($m[0]));
    $delta_str += strlen($to[$what][$n]) - strlen($m[0]) + 1;
    }
    }

    W C++ wyobrażam sobie tak:

    short delta_str = 0;
    sub_match match = matches[indexes[what][k]];
    for (auto m = match.begin(); m < match.end(); m++) {
    if (what == i_functions && k == 1) { // 2nd regexp for functions
    // check if a method call:
    string before = line.substr(m.position() - 2, 2);
    if (before == "->" || before == "::") {
    continue; // don't obfuscate now
    }
    }
    if (what == i_functions) { // case insensitive
    n = strvector_search(strtoupper(m.str()), from[what]);
    } else if (what == i_methods) { // case insensitive
    if (in_strvector(strtoupper(m.str()), from[i_actions])) { // action
    n = -1;
    } else {
    n = strvector_search(strtoupper(m.str()), from[what]);
    }
    } else { // case sensitive
    n = strvector_search(m.str(), from[what]);
    }
    if (n >= 0) {
    line = substr_replace(line, string("_").append(to[what][n]),
    m.position() + delta_str, strlen(m.str().c_str()));
    delta_str += strlen(to[what][n].c_str()) - strlen(m.str().c_str()) + 1;
    }
    }

    Ale sub_match nie zawiera metod begin() i end() więc mój kod się nie
    kompiluje. Prosiłbym bardzo o poprawienie kodu.

Podziel się

Poleć ten post znajomemu poleć

Wydrukuj ten post drukuj


Następne wpisy z tego wątku

Najnowsze wątki z tej grupy


Najnowsze wątki

Szukaj w grupach

Eksperci egospodarka.pl

1 1 1

Wpisz nazwę miasta, dla którego chcesz znaleźć jednostkę ZUS.

Wzory dokumentów

Bezpłatne wzory dokumentów i formularzy.
Wyszukaj i pobierz za darmo: