eGospodarka.pl
eGospodarka.pl poleca

eGospodarka.plGrupypl.comp.programmingproblem z wyrażeniem regularnym w C++ › Re: problem z wyrażeniem regularnym w C++
  • Data: 2020-04-07 19:07:37
    Temat: Re: problem z wyrażeniem regularnym w C++
    Od: RM <r...@w...pl> szukaj wiadomości tego autora
    [ pokaż wszystkie 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: