Comments (3)
I tried to reproduce this and my code works fine:
#include <string>
#include <vector>
#include <stdio.h>
#include <pire/easy.h>
Pire::Scanner scannerFor( std::string regexp ){
if ( !regexp.size() ) {
throw 1;
}
std::vector<Pire::wchar32> pattern;
Pire::Scanner s;
try {
Pire::Encodings::Utf8().FromLocal( regexp.c_str(), regexp.c_str() + regexp.size(), std::back_inserter(pattern) );
s = Pire::Lexer( pattern.begin(), pattern.end() )
.SetEncoding( Pire::Encodings::Utf8() )
.AddFeature( Pire::Features::CaseInsensitive() )
.Parse()
.Surround()
.Compile<Pire::Scanner>();
} catch ( ... ) {
throw 1;
}
return s;
}
int main() {
std::string r;
r = "(post|get|put|delete).*http/1\\.(1|0)\r\n.*\r\n\r\n";
Pire::Scanner sc = scannerFor(r);
std::string s =
"GET / HTTP/1.1\r\n"
"User-Agent: chrome\r\n"
"Host: ya.ru\r\n"
"Accept: /\r\n"
"Proxy-Connection: Keep-Alive\r\n\r\n";
Pire::Regexp rsc(sc);
bool a = rsc.Matches(s);
printf("%s\n", (a ? "match" : "no match"));
return 0;
}
from pire.
Test code is:
/* stl */
#include <string>
#include <vector>
#include <stdio.h>
#include <iostream>
#include <iomanip>
/* pire */
#include <pire/easy.h>
namespace pire_test {
class flow {
protected:
Pire::Scanner scannerFor( std::string regexp, bool useUtf8 ){
if ( !regexp.size() ) {
throw 1;
}
std::vector<Pire::wchar32> pattern;
Pire::Scanner s;
try {
Pire::Encodings::Utf8().FromLocal( regexp.c_str(), regexp.c_str() + regexp.size(), std::back_inserter(pattern) );
if ( useUtf8 ) {
s = Pire::Lexer( pattern.begin(), pattern.end() )
.SetEncoding( Pire::Encodings::Utf8() )
.AddFeature( Pire::Features::CaseInsensitive() )
.Parse()
.Surround()
.Compile<Pire::Scanner>();
} else {
s = Pire::Lexer( pattern.begin(), pattern.end() )
.AddFeature( Pire::Features::CaseInsensitive() )
.Parse()
.Surround()
.Compile<Pire::Scanner>();
}
} catch ( ... ) {
throw 1;
}
return s;
}
public:
void match( std::string s ) {
Pire::Regexp rsc(_scanner);
std::cout << std::left
<< "name: " << std::setw(10)<< _name
<< "useUtf8: " << std::setw(4) << ( _useUtf8 ? "YES" : "NO" )
<< "match: " << std::setw(4) << ( rsc.Matches(s) ? "YES" : "NO" )
<< std::endl;
}
public:
flow( std::string name, std::string r, bool useUtf8 ) :
_name(name),
_useUtf8(useUtf8)
{
_scanner = scannerFor( r, _useUtf8 );
}
~flow() {
}
private:
Pire::Scanner _scanner;
std::string _name;
bool _useUtf8;
};
} // end of namespace
std::string r("(post|get|put|delete).*http/1\\.(1|0)\r\n.*\r\n\r\n");
pire_test::flow flow1("global1", r, false );
pire_test::flow flow2("global2", r, true );
int main() {
std::string s =
"GET / HTTP/1.1\r\n"
"User-Agent: chrome\r\n"
"Host: ya.ru\r\n"
"Accept: /\r\n"
"Proxy-Connection: Keep-Alive\r\n\r\n";
pire_test::flow flow3("local1", r, false );
pire_test::flow flow4("local2", r, true );
flow1.match(s);
flow2.match(s);
flow3.match(s);
flow4.match(s);
return 0;
}
Use the pire library as a shared lib all is fine the result is:
name: global1 useUtf8: NO match: YES
name: global2 useUtf8: YES match: YES
name: local1 useUtf8: NO match: YES
name: local2 useUtf8: YES match: YES
Use the pire library as a static lib we have strange encoding problem
name: global1 useUtf8: NO match: YES
name: global2 useUtf8: YES match: NO
name: local1 useUtf8: NO match: YES
name: local2 useUtf8: YES match: YES
I've tried several others regexp to test for "global2 test" and I think the problem is related with ".", i.e
regexp "GET" - match
regexp "." - no match
from pire.
The problem was with the order of global vars initialization. This commit fixes the problem.
from pire.
Related Issues (20)
- Make pire_inline capable of cross-compiling regexps
- typo in docs HOT 1
- discrepancy in pigrep: it prints "(stdin)" if file is "-" and prints nothing if no file provided HOT 3
- can't build from the package produced by `make distcheck` because of missing file re_parser.y HOT 1
- add method Size() to class Lexer HOT 1
- fix build instructions for "On *nix, from the tarball"
- Lexer.Parse called multiple times results in errors HOT 2
- Make pire_inline capable of cross-compiling regexps
- pattern without ^ and $ matches nothing unless Surrounded
- Which Regexp syntax is used ? HOT 5
- Inconsistency in run.h: LongestSuffix uses Step, ShortestSuffix uses scanner.Next
- add LettersCount() to SlowScanner
- What is the purpose of LoadedScanner.m_actions?
- Compile Error HOT 2
- Conan package
- Change licence HOT 1
- unidata generation tool HOT 1
- Make a new release HOT 1
- Compilation error on Windows
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pire.