没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Boost.Regex
John Maddock
Copyright © 2007 John Maddock
Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at ht-
tp://www.boost.org/LICENSE_1_0.txt)
Table of Contents
Configuration ............................................................................................................................................................. 2
Compiler Setup ................................................................................................................................................... 2
Locale and traits class selection .............................................................................................................................. 3
Linkage Options .................................................................................................................................................. 3
Algorithm Selection ............................................................................................................................................. 3
Algorithm Tuning ................................................................................................................................................ 3
Building and Installing the Library .................................................................................................................................. 4
Introduction and Overview ............................................................................................................................................ 8
Unicode and Boost.Regex ............................................................................................................................................ 10
Understanding Marked Sub-Expressions and Captures ...................................................................................................... 11
Partial Matches .......................................................................................................................................................... 15
Regular Expression Syntax .......................................................................................................................................... 18
Perl Regular Expression Syntax ............................................................................................................................ 18
POSIX Extended Regular Expression Syntax .......................................................................................................... 27
POSIX Basic Regular Expression Syntax ................................................................................................................ 34
Character Class Names ....................................................................................................................................... 39
Character Classes that are Always Supported ................................................................................................... 39
Character classes that are supported by Unicode Regular Expressions .................................................................. 40
Collating Names ................................................................................................................................................ 42
Digraphs .................................................................................................................................................. 42
POSIX Symbolic Names ............................................................................................................................. 42
Named Unicode Characters .......................................................................................................................... 45
The Leftmost Longest Rule .................................................................................................................................. 45
Search and Replace Format String Syntax ....................................................................................................................... 46
Sed Format String Syntax .................................................................................................................................... 46
Perl Format String Syntax .................................................................................................................................... 47
Boost-Extended Format String Syntax .................................................................................................................... 48
Reference ................................................................................................................................................................. 49
basic_regex ....................................................................................................................................................... 49
match_results .................................................................................................................................................... 62
sub_match ........................................................................................................................................................ 68
regex_match ..................................................................................................................................................... 83
regex_search ..................................................................................................................................................... 87
regex_replace .................................................................................................................................................... 91
regex_iterator .................................................................................................................................................... 95
regex_token_iterator ......................................................................................................................................... 101
bad_expression ................................................................................................................................................ 109
syntax_option_type ........................................................................................................................................... 110
syntax_option_type Synopsis ...................................................................................................................... 110
Overview of syntax_option_type ................................................................................................................. 110
1
XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/
Options for Perl Regular Expressions ........................................................................................................... 111
Options for POSIX Extended Regular Expressions ......................................................................................... 112
Options for POSIX Basic Regular Expressions ............................................................................................... 113
Options for Literal Strings .......................................................................................................................... 114
match_flag_type .............................................................................................................................................. 115
error_type ....................................................................................................................................................... 117
regex_traits ..................................................................................................................................................... 118
Interfacing With Non-Standard String Types .......................................................................................................... 119
Working With Unicode and ICU String Types ................................................................................................ 119
Introduction to using Regex with ICU .................................................................................................. 119
Unicode regular expression types ........................................................................................................ 119
Unicode Regular Expression Algorithms ............................................................................................... 121
Unicode Aware Regex Iterators ........................................................................................................... 123
Using Boost Regex With MFC Strings .......................................................................................................... 129
Introduction to Boost.Regex and MFC Strings ....................................................................................... 129
Regex Types Used With MFC Strings ................................................................................................... 129
Regular Expression Creation From an MFC String ................................................................................. 130
Overloaded Algorithms For MFC String Types ....................................................................................... 130
Iterating Over the Matches Within An MFC String .................................................................................. 133
POSIX Compatible C API's ................................................................................................................................ 135
Concepts ........................................................................................................................................................ 138
charT Requirements .................................................................................................................................. 138
Traits Class Requirements .......................................................................................................................... 139
Iterator Rrequirements ............................................................................................................................... 141
Deprecated Interfaces ........................................................................................................................................ 141
regex_format (Deprecated) ......................................................................................................................... 141
regex_grep (Deprecated) ............................................................................................................................ 142
regex_split (deprecated) ............................................................................................................................. 148
High Level Class RegEx (Deprecated) .......................................................................................................... 150
Background Information ............................................................................................................................................ 156
Headers .......................................................................................................................................................... 156
Localization .................................................................................................................................................... 157
Thread Safety .................................................................................................................................................. 162
Test and Example Programs ............................................................................................................................... 163
References and Further Information ..................................................................................................................... 164
FAQ ............................................................................................................................................................... 165
Performance .................................................................................................................................................... 166
Standards Conformance ..................................................................................................................................... 166
Redistributables ............................................................................................................................................... 168
Acknowledgements .......................................................................................................................................... 168
History ........................................................................................................................................................... 169
Configuration
Compiler Setup
You shouldn't need to do anything special to configure Boost.Regex for use with your compiler - the Boost.Config subsystem should
already take care of it, if you do have problems (or you are using a particularly obscure compiler or platform) then Boost.Config has a
configure script that you can run.
2
Boost.Regex
XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/
Locale and traits class selection
The following macros (see user.hpp) control how Boost.Regex interacts with the user's locale:
descriptionmacro
Forces Boost.Regex to use the global C locale in its traits class support: this is now de-
precated in favour of the C++ locale.
BOOST_REGEX_USE_C_LOCALE
Forces Boost.Regex to use std::locale in it's default traits class, regular expressions can
then be imbued with an instance specific locale. This is the default behaviour on non-
Windows platforms.
BOOST_REGEX_USE_CPP_LOCALE
Tells Boost.Regex not to use any Win32 API's even when available (implies
BOOST_REGEX_USE_CPP_LOCALE unless BOOST_REGEX_USE_C_LOCALE is
set).
BOOST_REGEX_NO_W32
Linkage Options
descriptionmacro
For Microsoft and Borland C++ builds, this tells Boost.Regex that it should link to the dll build
of the Boost.Regex. By default boost.regex will link to its static library build, even if the dynamic
C runtime library is in use.
BOOST_REGEX_DYN_LINK
For Microsoft and Borland C++ builds, this tells Boost.Regex that it should not automatically select
the library to link to.
BOOST_REGEX_NO_LIB
Algorithm Selection
descriptionmacro
Tells Boost.Regex to use a stack-recursive matching algorithm. This is generally the fastest
option (although there is very little in it), but can cause stack overflow in extreme cases, on
Win32 this can be handled safely, but this is not the case on other platforms.
BOOST_REGEX_RECURSIVE
Tells Boost.Regex to use a non-stack recursive matching algorithm, this can be slightly slower
than the alternative, but is always safe no matter how pathological the regular expression. This
is the default on non-Win32 platforms.
BOOST_REGEX_NON_RECURS-
IVE
Algorithm Tuning
The following option applies only if BOOST_REGEX_RECURSIVE is set.
descriptionmacro
Tells Boost.Regex that Microsoft style __try - __except blocks are supported,
and can be used to safely trap stack overflow.
BOOST_REGEX_HAS_MS_STACK_GUARD
3
Boost.Regex
XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/
The following options apply only if BOOST_REGEX_NON_RECURSIVE is set.
descriptionmacro
In non-recursive mode, Boost.Regex uses largish blocks of memory to act as a stack
for the state machine, the larger the block size then the fewer allocations that will
BOOST_REGEX_BLOCKSIZE
take place. This defaults to 4096 bytes, which is large enough to match the vast ma-
jority of regular expressions without further allocations, however, you can choose
smaller or larger values depending upon your platforms characteristics.
Tells Boost.Regex how many blocks of size BOOST_REGEX_BLOCKSIZE it is
permitted to use. If this value is exceeded then Boost.Regex will stop trying to find
BOOST_REGEX_MAX_BLOCKS
a match and throw a std::runtime_error. Defaults to 1024, don't forget to tweek this
value if you alter BOOST_REGEX_BLOCKSIZE by much.
Tells Boost.Regex how many memory blocks to store in it's internal cache - memory
blocks are taken from this cache rather than by calling ::operator new. Generally
BOOST_REGEX_MAX_CACHE_BLOCKS
speeking this can be an order of magnitude faster than calling ::opertator new each
time a memory block is required, but has the downside that Boost.Regex can end up
caching a large chunk of memory (by default up to 16 blocks each of
BOOST_REGEX_BLOCKSIZE size). If memory is tight then try defining this to 0
(disables all caching), or if that is too slow, then a value of 1 or 2, may be sufficient.
On the other hand, on large multi-processor, multi-threaded systems, you may find
that a higher value is in order.
Building and Installing the Library
When you extract the library from its zip file, you must preserve its internal directory structure (for example by using the -d option when
extracting). If you didn't do that when extracting, then you'd better stop reading this, delete the files you just extracted, and try again!
This library should not need configuring before use; most popular compilers/standard libraries/platforms are already supported "as is".
If you do experience configuration problems, or just want to test the configuration with your compiler, then the process is the same as
for all of boost; see the configuration library documentation.
The library will encase all code inside namespace boost.
Unlike some other template libraries, this library consists of a mixture of template code (in the headers) and static code and data (in cpp
files). Consequently it is necessary to build the library's support code into a library or archive file before you can use it, instructions for
specific platforms are as follows:
Building with bjam
This is now the preferred method for building and installing this library, please refer to the getting started guide for more information.
Building With Unicode and ICU Support
A default build of this library does not enable Unciode support via ICU. There is no need to enable this support if you don't need it, but
if you use ICU for your Unicode support already, and want to work with Unicode-aware regular expressions then read on.
Most of the information you will need is in the getting started guide, the only additional step you need to take is to tell bjam that you
want Boost.Regex to use ICU and optionally to tell bjam where ICU is located.
4
Boost.Regex
XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/
If you're building on a Unix-like platform, and ICU is already installed in you're compilers search path (with an install prefix of /usr
or /usr/local for example), then set the environment variable HAVE_ICU to enable ICU support. For example you might build with
the command line:
bjam -sHAVE_ICU=1 --toolset=toolset-name install
If ICU is not already in your compiler's path then you need to set the environment variable ICU_PATH to point to the root directory of
your ICU installation, for example if ICU was installed to /usr/local/icu/3.3 you might use:
bjam -sICU_PATH=/usr/local/icu/3.3 --toolset=toolset-name install
Note that ICU is a C++ library just like Boost is, as such your copy of ICU must have been built with the same C++ compiler (and
compiler version) that you are using to build Boost. Boost.Regex will not work correctly unless you ensure that this is the case: it is up
to you to ensure that the version of ICU you are using is binary compatible with the toolset you use to build Boost.
Building via makefiles
Borland C++ Builder:
•
Open up a console window and change to the <boost>\libs\regex\build directory.
• Select the appropriate makefile (bcb4.mak for C++ Builder 4, bcb5.mak for C++ Builder 5, and bcb6.mak for C++ Builder 6).
• Invoke the makefile (pass the full path to your version of make if you have more than one version installed, the makefile relies on the
path to make to obtain your C++ Builder installation directory and tools) for example:
make -fbcb5.mak
The build process will build a variety of .lib and .dll files (the exact number depends upon the version of Borland's tools you are using)
the .lib and dll files will be in a sub-directory called bcb4 or bcb5 depending upon the makefile used. To install the libraries into your
development system use:
make -fbcb5.mak install
library files will be copied to <BCROOT>/lib and the dll's to <BCROOT>/bin, where <BCROOT> corresponds to the install path of
your Borland C++ tools.
You may also remove temporary files created during the build process (excluding lib and dll files) by using:
make -fbcb5.mak clean
Finally when you use Boost.Regex it is only necessary for you to add the <boost> root director to your list of include directories for
that project. It is not necessary for you to manually add a .lib file to the project; the headers will automatically select the correct .lib file
for your build mode and tell the linker to include it. There is one caveat however: the library can not tell the difference between VCL
and non-VCL enabled builds when building a GUI application from the command line, if you build from the command line with the 5.5
command line tools then you must define the pre-processor symbol _NO_VCL in order to ensure that the correct link libraries are selected:
the C++ Builder IDE normally sets this automatically. Hint, users of the 5.5 command line tools may want to add a -D_NO_VCL to
bcc32.cfg in order to set this option permanently.
If you would prefer to do a dynamic link to the regex libraries when using the dll runtime then define BOOST_REGEX_DYN_LINK
(you must do this if you want to use Boost.Regex in multiple dll's), otherwise Boost.Regex will be statically linked by default.
5
Boost.Regex
XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/
剩余169页未读,继续阅读
资源评论
- yunsicai2012-11-22全是英文,没看懂!
- 香草天空2014-04-08还是有一定参考价值的
cbwxl
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功