-
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.
Następne wpisy z tego wątku
- 08.04.20 15:49 RM
- 08.04.20 16:39 RM
- 09.04.20 21:44 Wojciech Muła
Najnowsze wątki z tej grupy
- Bibl. Qt jest sztucznie ograniczona - jest nieprzydatna do celów komercyjnych
- Co sciaga kretynow
- AEiC 2024 - Ada-Europe conference - Deadlines Approaching
- Jakie są dobre zasady programowania programów opartych na wtyczkach?
- sprawdzanie słów kluczowych dot. zła
- Re: W czym sie teraz pisze programy??
- Re: (PDF) Surgical Pathology of Non-neoplastic Gastrointestinal Diseases by Lizhi Zhang
- CfC 28th Ada-Europe Int. Conf. Reliable Software Technologies
- Młodzi programiści i tajna policja
- Ada 2022 Language Reference Manual to be Published by Springer
- Press Release - AEiC 2023, Ada-Europe Reliable Softw. Technol.
- Ada-Europe - AEiC 2023 early registration deadline approaching
- Ada-Europe Int.Conf. Reliable Software Technologies, AEiC 2023
- Ile cykli zajmuje mnożenie liczb 64-bitowych?
- Ideologia Polskiego Programisty wer.3
Najnowsze wątki
- 2024-05-04 Lunar Rover był elektrykiem. Ważył 35 kg Zasięg 80 km Na Księżycu w 1971 r.
- 2024-05-04 Marki => ERP Implementer <=
- 2024-05-04 Gdańsk => Head of International Freight Forwarding Department <=
- 2024-05-04 Marki => Wdrożeniowiec ERP <=
- 2024-05-03 Warszawa => Sprzedawca usług rekrutacyjnych <=
- 2024-05-03 Warszawa => Mid/Senior QA Engineer <=
- 2024-05-03 Warszawa => Mid/Senior QA Engineer <=
- 2024-05-03 Warszawa => Senior PHP Developer (Symfony) <=
- 2024-05-03 Rzeszów => UX/UI Designer <=
- 2024-05-03 Giertych przetarł szlak: byli członkowie zarządu Orlenu śledztwa prokuratorskie obserwują z zagranicy
- 2024-05-03 Warszawa => Senior Rust Software Engineer <=
- 2024-05-03 Kraków => UX/UI Designer <=
- 2024-05-03 Warszawa => International freight forwarder <=
- 2024-05-02 Silnik Stirlinga - energia mechaniczna wytwarzana z ciepła bez dostarczania paliwa!
- 2024-05-02 Kraków => Senior .Net Programmer <=