#include <boost/xpressive/xpressive.hpp> #include <iostream> using namespace std ; using namespace boost :: xpressive ; int main ( int argc, char * argv [ ] ) { sregex xpr = sregex :: compile ( "" , regex_constants :: icase ) ; smatch match ; string str ( " !" ) ; if ( regex_search ( str, match, xpr ) ) cout << "icase ok" << endl ; else cout << "icase fail" << endl ; return 0 ; }
#include <boost/xpressive/xpressive.hpp> #include <iostream> using namespace std ; using namespace boost :: xpressive ; int main ( int argc, char * argv [ ] ) { sregex xpr = sregex :: compile ( "" , regex_constants :: icase ) ; smatch match ; string str ( " !" ) ; if ( regex_search ( str, match, xpr ) ) cout << "icase ok" << endl ; else cout << "icase fail" << endl ; return 0 ; }
#include <boost/xpressive/xpressive.hpp> #include <iostream> using namespace std ; using namespace boost :: xpressive ; int main ( int argc, char * argv [ ] ) { sregex xpr = sregex :: compile ( "" , regex_constants :: icase ) ; smatch match ; string str ( " !" ) ; if ( regex_search ( str, match, xpr ) ) cout << "icase ok" << endl ; else cout << "icase fail" << endl ; return 0 ; }
#include <boost/xpressive/xpressive.hpp> #include <iostream> using namespace std ; using namespace boost :: xpressive ; int main ( int argc, char * argv [ ] ) { sregex xpr = sregex :: compile ( "" , regex_constants :: icase ) ; smatch match ; string str ( " !" ) ; if ( regex_search ( str, match, xpr ) ) cout << "icase ok" << endl ; else cout << "icase fail" << endl ; return 0 ; }
#include <boost/xpressive/xpressive.hpp> #include <iostream> using namespace std ; using namespace boost :: xpressive ; int main ( int argc, char * argv [ ] ) { sregex xpr = sregex :: compile ( "" , regex_constants :: icase ) ; smatch match ; string str ( " !" ) ; if ( regex_search ( str, match, xpr ) ) cout << "icase ok" << endl ; else cout << "icase fail" << endl ; return 0 ; }
#include <boost/xpressive/xpressive.hpp> #include <iostream> using namespace std ; using namespace boost :: xpressive ; int main ( int argc, char * argv [ ] ) { sregex xpr = sregex :: compile ( "" , regex_constants :: icase ) ; smatch match ; string str ( " !" ) ; if ( regex_search ( str, match, xpr ) ) cout << "icase ok" << endl ; else cout << "icase fail" << endl ; return 0 ; }
#include <boost/xpressive/xpressive.hpp> #include <iostream> using namespace std ; using namespace boost :: xpressive ; int main ( int argc, char * argv [ ] ) { sregex xpr = sregex :: compile ( "" , regex_constants :: icase ) ; smatch match ; string str ( " !" ) ; if ( regex_search ( str, match, xpr ) ) cout << "icase ok" << endl ; else cout << "icase fail" << endl ; return 0 ; }
#include <boost/xpressive/xpressive.hpp> #include <iostream> using namespace std ; using namespace boost :: xpressive ; int main ( int argc, char * argv [ ] ) { sregex xpr = sregex :: compile ( "" , regex_constants :: icase ) ; smatch match ; string str ( " !" ) ; if ( regex_search ( str, match, xpr ) ) cout << "icase ok" << endl ; else cout << "icase fail" << endl ; return 0 ; }
#include <boost/xpressive/xpressive.hpp> #include <iostream> using namespace std ; using namespace boost :: xpressive ; int main ( int argc, char * argv [ ] ) { sregex xpr = sregex :: compile ( "" , regex_constants :: icase ) ; smatch match ; string str ( " !" ) ; if ( regex_search ( str, match, xpr ) ) cout << "icase ok" << endl ; else cout << "icase fail" << endl ; return 0 ; }
#include <boost/xpressive/xpressive.hpp> #include <iostream> using namespace std ; using namespace boost :: xpressive ; int main ( int argc, char * argv [ ] ) { sregex xpr = sregex :: compile ( "" , regex_constants :: icase ) ; smatch match ; string str ( " !" ) ; if ( regex_search ( str, match, xpr ) ) cout << "icase ok" << endl ; else cout << "icase fail" << endl ; return 0 ; }
#include <boost/xpressive/xpressive.hpp> #include <iostream> using namespace std ; using namespace boost :: xpressive ; int main ( int argc, char * argv [ ] ) { sregex xpr = sregex :: compile ( "" , regex_constants :: icase ) ; smatch match ; string str ( " !" ) ; if ( regex_search ( str, match, xpr ) ) cout << "icase ok" << endl ; else cout << "icase fail" << endl ; return 0 ; }
#include <boost/xpressive/xpressive.hpp> #include <iostream> using namespace std ; using namespace boost :: xpressive ; int main ( int argc, char * argv [ ] ) { sregex xpr = sregex :: compile ( "" , regex_constants :: icase ) ; smatch match ; string str ( " !" ) ; if ( regex_search ( str, match, xpr ) ) cout << "icase ok" << endl ; else cout << "icase fail" << endl ; return 0 ; }
#include <boost/xpressive/xpressive.hpp> #include <iostream> using namespace std ; using namespace boost :: xpressive ; int main ( int argc, char * argv [ ] ) { sregex xpr = sregex :: compile ( "" , regex_constants :: icase ) ; smatch match ; string str ( " !" ) ; if ( regex_search ( str, match, xpr ) ) cout << "icase ok" << endl ; else cout << "icase fail" << endl ; return 0 ; }
#include <boost/xpressive/xpressive.hpp> #include <iostream> using namespace std ; using namespace boost :: xpressive ; int main ( int argc, char * argv [ ] ) { sregex xpr = sregex :: compile ( "" , regex_constants :: icase ) ; smatch match ; string str ( " !" ) ; if ( regex_search ( str, match, xpr ) ) cout << "icase ok" << endl ; else cout << "icase fail" << endl ; return 0 ; }
#include <boost/xpressive/xpressive.hpp> #include <iostream> using namespace std ; using namespace boost :: xpressive ; int main ( int argc, char * argv [ ] ) { sregex xpr = sregex :: compile ( "" , regex_constants :: icase ) ; smatch match ; string str ( " !" ) ; if ( regex_search ( str, match, xpr ) ) cout << "icase ok" << endl ; else cout << "icase fail" << endl ; return 0 ; }
- // set global localization
- std :: locale cp1251_locale ( "en_US.CP1251" ) ;
- std :: locale :: global ( cp1251_locale ) ;
- std :: locale cp1251_locale ( "en_US.CP1251" ) ;
- sregex_compiler compiler ;
- // tell the regex compiler what localization to use
- compiler. imbue ( cp1251_locale ) ;
- sregex xpr = compiler. compile ( "world" , regex_constants :: icase ) ;
- #include <boost / xpressive / xpressive.hpp>
- #include <iostream>
- using namespace std ;
- using namespace boost :: xpressive ;
- / ** @ brief A very simplified example of the ctype facet for working correctly with
- * Encoding Cp1251 * /
- class ctype_cp1251 : public ctype < char >
- {
- public :
- / ** @ breif mask in ctype_base is an enumeration of all possible types.
- * characters - alpha, digit, ... * /
- typedef typename ctype < char > :: ctype_base :: mask mask ;
- // for brevity, let's rename the constants
- enum {
- alpha = ctype < char > :: alpha ,
- lower = ctype < char > :: lower ,
- punct = ctype < char > :: punct
- // other masks
- } ;
- / ** @ brief Main constructor. r - characterizes the area of ​​life
- * cell. For details, see the book of Straustrup. * /
- ctype_cp1251 ( size_t r = 0 )
- {
- // initialize the table of masks. The index is the negative part of the char.
- // That is, ext_tab [1] - the mask for the character char (-1) - 'I'
- ext_tab [ 0 ] = 0 ;
- for ( size_t i = 1 ; i <= 32 ; ++ i )
- ext_tab [ i ] = alpha | lower ;
- for ( size_t i = 33 ; i <= 64 ; ++ i )
- ext_tab [ i ] = alpha | upper ;
- // ... the rest of the characters in this example are uninteresting
- for ( size_t i = 65 ; i <= 128 ; ++ i )
- ext_tab [ i ] = punct ;
- }
- ~ ctype_cp1251 ( )
- { }
- protected :
- / ** @ brief Answers the question whether the character c matches the mask m * /
- virtual bool is ( mask m, char c ) const
- {
- if ( 0 <= c && c <= 127 )
- return ctype < char > :: is ( m, c ) ;
- else if ( - 128 <= c && c < 0 )
- return ext_tab [ static_cast < size_t > ( c * - 1 ) ] & m ;
- }
- / ** @ brief Converts the character c to uppercase * /
- virtual char do_toupper ( char c ) const
- {
- if ( 0 <= c && c <= 127 )
- return ctype < char > :: do_toupper ( c ) ;
- else if ( is ( lower, c ) )
- return c - 32 ;
- return c ;
- }
- / ** @ brief Converts the character c to lower case * /
- virtual char do_tolower ( char c ) const
- {
- if ( 0 <= c && c <= 127 )
- return ctype < char > :: do_tolower ( c ) ;
- else if ( is ( upper, c ) )
- return c + 32 ;
- return c ;
- }
- // not to complicate the example, we will not override the rest
- // virtual functions
- private :
- // ban on copying
- ctype_cp1251 ( const ctype_cp1251 & ) ;
- const ctype_cp1251 & operator = ( const ctype_cp1251 & ) ;
- mask ext_tab [ 129 ] ; // @ <masks of the extended part of the code table CP1251
- } ;
- int main ( int argc, char * argv [ ] )
- {
- // create an instance of the cell
- ctype < char > * ctype_cp1251_facet = new ctype_cp1251 ( ) ;
- // Create a new localization based on the current, using
- // defined above facet. You can define a global
- // localization with the described facet, then all the classes and
- // functions will use it.
- locale cp1251_locale ( locale ( "" ) , ctype_cp1251_facet ) ;
- // create regex compilers with specific localization
- sregex_compiler compiler ;
- compiler. imbue ( cp1251_locale ) ;
- sregex xpr = compiler. compile ( "world" , regex_constants :: icase ) ;
- smatch match ;
- string str ( "HELLO WORLD!" ) ;
- if ( regex_search ( str, match, xpr ) )
- cout << "icase ok" << endl ;
- else
- cout << "icase fail" << endl ;
- return 0 ;
- }
Source: https://habr.com/ru/post/104417/
All Articles