1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-05-09 09:34:06 +02:00

*** empty log message ***

This commit is contained in:
rmaddy 2003-04-22 23:49:47 +00:00
parent 2ff5feba78
commit ae9770692c
32 changed files with 5773 additions and 0 deletions

340
license/COPYING Normal file
View File

@ -0,0 +1,340 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

504
license/COPYING.LIB Normal file
View File

@ -0,0 +1,504 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

View File

@ -0,0 +1,66 @@
/*
* gnu/regexp/CharIndexed.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
/**
* Defines the interface used internally so that different types of source
* text can be accessed in the same way. Built-in concrete classes provide
* support for String, StringBuffer, InputStream and char[] types.
* A class that is CharIndexed supports the notion of a cursor within a
* block of text. The cursor must be able to be advanced via the move()
* method. The charAt() method returns the character at the cursor position
* plus a given offset.
*
* @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
*/
public interface CharIndexed
{
/**
* Defines a constant (0xFFFF was somewhat arbitrarily chosen)
* that can be returned by the charAt() function indicating that
* the specified index is out of range.
*/
char OUT_OF_BOUNDS = '\uFFFF';
/**
* Returns the character at the given offset past the current cursor
* position in the input. The index of the current position is zero.
* It is possible for this method to be called with a negative index.
* This happens when using the '^' operator in multiline matching mode
* or the '\b' or '\<' word boundary operators. In any case, the lower
* bound is currently fixed at -2 (for '^' with a two-character newline).
*
* @param index the offset position in the character field to examine
* @return the character at the specified index, or the OUT_OF_BOUNDS
* character defined by this interface.
*/
char charAt(int index);
/**
* Shifts the input buffer by a given number of positions. Returns
* true if the new cursor position is valid.
*/
boolean move(int index);
/**
* Returns true if the most recent move() operation placed the cursor
* position at a valid position in the input.
*/
boolean isValid();
}

View File

@ -0,0 +1,49 @@
/*
* gnu/regexp/CharIndexedCharArray.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
import java.io.Serializable;
class CharIndexedCharArray implements CharIndexed, Serializable
{
private char[] s;
private int anchor;
CharIndexedCharArray(char[] str, int index)
{
s = str;
anchor = index;
}
public char charAt(int index)
{
int pos = anchor + index;
return ((pos < s.length) && (pos >= 0)) ? s[pos] : OUT_OF_BOUNDS;
}
public boolean isValid()
{
return (anchor < s.length);
}
public boolean move(int index)
{
return ((anchor += index) < s.length);
}
}

View File

@ -0,0 +1,49 @@
/*
* gnu/regexp/CharIndexedCharArray.java
* Copyright (C) 2003 Rick Maddy
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
import java.io.Serializable;
class CharIndexedCharSequence implements CharIndexed, Serializable
{
private CharSequence seq;
private int anchor;
CharIndexedCharSequence(CharSequence seq, int index)
{
this.seq = seq;
anchor = index;
}
public char charAt(int index)
{
int pos = anchor + index;
return ((pos < seq.length()) && (pos >= 0)) ? seq.charAt(pos) : OUT_OF_BOUNDS;
}
public boolean isValid()
{
return (anchor < seq.length());
}
public boolean move(int index)
{
return ((anchor += index) < seq.length());
}
}

View File

@ -0,0 +1,171 @@
/*
* gnu/regexp/CharIndexedReader.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.io.IOException;
// TODO: move(x) shouldn't rely on calling next() x times
class CharIndexedInputStream implements CharIndexed
{
private static final int BUFFER_INCREMENT = 1024;
private static final int UNKNOWN = Integer.MAX_VALUE; // value for end
private BufferedInputStream br;
// so that we don't try to reset() right away
private int index = -1;
private int bufsize = BUFFER_INCREMENT;
private int end = UNKNOWN;
private char cached = OUT_OF_BOUNDS;
// Big enough for a \r\n pair
// lookBehind[0] = most recent
// lookBehind[1] = second most recent
private char[] lookBehind = new char[]{OUT_OF_BOUNDS, OUT_OF_BOUNDS};
CharIndexedInputStream(InputStream str, int index)
{
if (str instanceof BufferedInputStream)
br = (BufferedInputStream)str;
else
br = new BufferedInputStream(str, BUFFER_INCREMENT);
next();
if (index > 0) move(index);
}
private boolean next()
{
if (end == 1) return false;
end--; // closer to end
try
{
if (index != -1)
{
br.reset();
}
int i = br.read();
br.mark(bufsize);
if (i == -1)
{
end = 1;
cached = OUT_OF_BOUNDS;
return false;
}
cached = (char)i;
index = 1;
}
catch (IOException e)
{
e.printStackTrace();
cached = OUT_OF_BOUNDS;
return false;
}
return true;
}
public char charAt(int index)
{
if (index == 0)
{
return cached;
}
else if (index >= end)
{
return OUT_OF_BOUNDS;
}
else if (index == -1)
{
return lookBehind[0];
}
else if (index == -2)
{
return lookBehind[1];
}
else if (index < -2)
{
return OUT_OF_BOUNDS;
}
else if (index >= bufsize)
{
// Allocate more space in the buffer.
try
{
while (bufsize <= index) bufsize += BUFFER_INCREMENT;
br.reset();
br.mark(bufsize);
br.skip(index - 1);
}
catch (IOException e)
{
}
}
else if (this.index != index)
{
try
{
br.reset();
br.skip(index - 1);
}
catch (IOException e)
{
}
}
char ch = OUT_OF_BOUNDS;
try
{
int i = br.read();
this.index = index + 1; // this.index is index of next pos relative to charAt(0)
if (i == -1)
{
// set flag that next should fail next time?
end = index;
return ch;
}
ch = (char)i;
}
catch (IOException ie)
{
}
return ch;
}
public boolean move(int index)
{
// move read position [index] clicks from 'charAt(0)'
boolean retval = true;
while (retval && (index-- > 0)) retval = next();
return retval;
}
public boolean isValid()
{
return (cached != OUT_OF_BOUNDS);
}
}

View File

@ -0,0 +1,184 @@
/*
* gnu/regexp/CharIndexedReader.java
* Copyright (C) 2001 Lee Sau Dan
* Based on gnu.regexp.CharIndexedInputStream by Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
import java.io.Reader;
import java.io.BufferedReader;
import java.io.IOException;
// TODO: move(x) shouldn't rely on calling next() x times
class CharIndexedReader implements CharIndexed
{
private static final int BUFFER_INCREMENT = 1024;
private static final int UNKNOWN = Integer.MAX_VALUE; // value for end
private final BufferedReader br;
// so that we don't try to reset() right away
private int index = -1;
private int bufsize = BUFFER_INCREMENT;
private int end = UNKNOWN;
private char cached = OUT_OF_BOUNDS;
// Big enough for a \r\n pair
// lookBehind[0] = most recent
// lookBehind[1] = second most recent
private char[] lookBehind = new char[]{OUT_OF_BOUNDS, OUT_OF_BOUNDS};
CharIndexedReader(Reader reader, int index)
{
if (reader instanceof BufferedReader)
{
br = (BufferedReader)reader;
}
else
{
br = new BufferedReader(reader, BUFFER_INCREMENT);
}
next();
if (index > 0) move(index);
}
private boolean next()
{
lookBehind[1] = lookBehind[0];
lookBehind[0] = cached;
if (end == 1)
{
cached = OUT_OF_BOUNDS;
return false;
}
end--; // closer to end
try
{
if (index != -1)
{
br.reset();
}
int i = br.read();
br.mark(bufsize);
if (i == -1)
{
end = 1;
cached = OUT_OF_BOUNDS;
return false;
}
// convert the byte read into a char
cached = (char)i;
index = 1;
}
catch (IOException e)
{
e.printStackTrace();
cached = OUT_OF_BOUNDS;
return false;
}
return true;
}
public char charAt(int index)
{
if (index == 0)
{
return cached;
}
else if (index >= end)
{
return OUT_OF_BOUNDS;
}
else if (index >= bufsize)
{
// Allocate more space in the buffer.
try
{
while (bufsize <= index) bufsize += BUFFER_INCREMENT;
br.reset();
br.mark(bufsize);
br.skip(index - 1);
}
catch (IOException e)
{
}
}
else if (this.index != index)
{
try
{
br.reset();
br.skip(index - 1);
}
catch (IOException e)
{
}
}
else if (index == -1)
{
return lookBehind[0];
}
else if (index == -2)
{
return lookBehind[1];
}
else if (index < -2)
{
return OUT_OF_BOUNDS;
}
char ch = OUT_OF_BOUNDS;
try
{
int i = br.read();
this.index = index + 1; // this.index is index of next pos relative to charAt(0)
if (i == -1)
{
// set flag that next should fail next time?
end = index;
return ch;
}
ch = (char)i;
}
catch (IOException ie)
{
}
return ch;
}
public boolean move(int index)
{
// move read position [index] clicks from 'charAt(0)'
boolean retval = true;
while (retval && (index-- > 0)) retval = next();
return retval;
}
public boolean isValid()
{
return (cached != OUT_OF_BOUNDS);
}
}

View File

@ -0,0 +1,51 @@
/*
* gnu/regexp/CharIndexedString.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
import java.io.Serializable;
class CharIndexedString implements CharIndexed, Serializable
{
private String s;
private int anchor;
private int len;
CharIndexedString(String str, int index)
{
s = str;
len = s.length();
anchor = index;
}
public char charAt(int index)
{
int pos = anchor + index;
return ((pos < len) && (pos >= 0)) ? s.charAt(pos) : OUT_OF_BOUNDS;
}
public boolean isValid()
{
return (anchor < len);
}
public boolean move(int index)
{
return ((anchor += index) < len);
}
}

View File

@ -0,0 +1,49 @@
/*
* gnu/regexp/CharIndexedStringBuffer.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
import java.io.Serializable;
class CharIndexedStringBuffer implements CharIndexed, Serializable
{
private StringBuffer s;
private int anchor;
CharIndexedStringBuffer(StringBuffer str, int index)
{
s = str;
anchor = index;
}
public char charAt(int index)
{
int pos = anchor + index;
return ((pos < s.length()) && (pos >= 0)) ? s.charAt(pos) : OUT_OF_BOUNDS;
}
public boolean isValid()
{
return (anchor < s.length());
}
public boolean move(int index)
{
return ((anchor += index) < s.length());
}
}

View File

@ -0,0 +1,22 @@
# Localized error messages for gnu.regexp
# Prefix for REException messages
error.prefix=At position {0} in regular expression pattern:
# REException (parse error) messages
repeat.assertion=repeated token is zero-width assertion
repeat.chained=attempted to repeat a token that is already repeated
repeat.no.token=quantifier (?*+{}) without preceding token
repeat.empty.token=repeated token may be empty
unmatched.brace=unmatched brace
unmatched.bracket=unmatched bracket
unmatched.paren=unmatched parenthesis
interval.no.end=expected end of interval
class.no.end=expected end of character class
subexpr.no.end=expected end of subexpression
interval.order=interval minimum is greater than maximum
interval.error=interval is empty or contains illegal chracters
ends.with.backslash=backslash at end of pattern
# RESyntax message
syntax.final=Syntax has been declared final and cannot be modified

1506
src/gnu/regexp/RE.java Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,169 @@
/*
* gnu/regexp/REException.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
import java.text.MessageFormat;
/**
* This is the regular expression exception class. An exception of this type
* defines the three attributes:
* <OL>
* <LI> A descriptive message of the error.
* <LI> An integral type code equivalent to one of the statically
* defined symbols listed below.
* <LI> The approximate position in the input string where the error
* occurred.
* </OL>
*
* @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
*/
public class REException extends Exception
{
private int type;
private int pos;
// Error conditions from GNU regcomp(3) manual
/**
* Error flag.
* Invalid use of repetition operators such as using
* `*' as the first character.
*/
public static final int REG_BADRPT = 1;
/**
* Error flag.
* Invalid use of back reference operator.
*/
public static final int REG_BADBR = 2;
/**
* Error flag.
* Un-matched brace interval operators.
*/
public static final int REG_EBRACE = 3;
/**
* Error flag.
* Un-matched bracket list operators.
*/
public static final int REG_EBRACK = 4;
/**
* Error flag.
* Invalid use of the range operator, eg. the ending
* point of the range occurs prior to the starting
* point.
*/
public static final int REG_ERANGE = 5;
/**
* Error flag.
* Unknown character class name. <B>Not implemented</B>.
*/
public static final int REG_ECTYPE = 6;
/**
* Error flag.
* Un-matched parenthesis group operators.
*/
public static final int REG_EPAREN = 7;
/**
* Error flag.
* Invalid back reference to a subexpression.
*/
public static final int REG_ESUBREG = 8;
/**
* Error flag.
* Non specific error. <B>Not implemented</B>.
*/
public static final int REG_EEND = 9;
/**
* Error flag.
* Invalid escape sequence. <B>Not implemented</B>.
*/
public static final int REG_ESCAPE = 10;
/**
* Error flag.
* Invalid use of pattern operators such as group or list.
*/
public static final int REG_BADPAT = 11;
/**
* Error flag.
* Compiled regular expression requires a pattern
* buffer larger than 64Kb. <B>Not implemented</B>.
*/
public static final int REG_ESIZE = 12;
/**
* Error flag.
* The regex routines ran out of memory. <B>Not implemented</B>.
*/
public static final int REG_ESPACE = 13;
REException(String msg, int type, int position)
{
super(msg);
this.type = type;
this.pos = position;
}
/**
* Returns the type of the exception, one of the constants listed above.
*/
public int getType()
{
return type;
}
/**
* Returns the position, relative to the string or character array being
* compiled, where the error occurred. This position is generally the point
* where the error was detected, not necessarily the starting index of
* a bad subexpression.
*/
public int getPosition()
{
return pos;
}
/**
* Reports the descriptive message associated with this exception
* as well as its index position in the string or character array
* being compiled.
*/
public String getMessage()
{
Object[] args = {new Integer(pos)};
StringBuffer sb = new StringBuffer();
String prefix = RE.getLocalizedMessage("error.prefix");
sb.append(MessageFormat.format(prefix, args));
sb.append('\n');
sb.append(super.getMessage());
return sb.toString();
}
}

View File

@ -0,0 +1,132 @@
/*
* gnu/regexp/REFilterInputStream.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
import java.io.FilterInputStream;
import java.io.InputStream;
/**
* Replaces instances of a given RE found within an InputStream
* with replacement text. The replacements are interpolated into the
* stream when a match is found.
*
* @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
* @deprecated This class cannot properly handle all character
* encodings. For proper handling, use the REFilterReader
* class instead.
*/
public class REFilterInputStream extends FilterInputStream
{
private RE expr;
private String replace;
private String buffer;
private int bufpos;
private int offset;
private CharIndexedInputStream stream;
/**
* Creates an REFilterInputStream. When reading from this stream,
* occurrences of patterns matching the supplied regular expression
* will be replaced with the supplied replacement text (the
* metacharacters $0 through $9 may be used to refer to the full
* match or subexpression matches).
*
* @param stream The InputStream to be filtered.
* @param expr The regular expression to search for.
* @param replace The text pattern to replace matches with.
*/
public REFilterInputStream(InputStream stream, RE expr, String replace)
{
super(stream);
this.stream = new CharIndexedInputStream(stream, 0);
this.expr = expr;
this.replace = replace;
}
/**
* Reads the next byte from the stream per the general contract of
* InputStream.read(). Returns -1 on error or end of stream.
*/
public int read()
{
// If we have buffered replace data, use it.
if ((buffer != null) && (bufpos < buffer.length()))
{
return (int)buffer.charAt(bufpos++);
}
// check if input is at a valid position
if (!stream.isValid()) return -1;
REMatch mymatch = new REMatch(expr.getNumSubs(), offset, 0);
if (expr.match(stream, mymatch))
{
mymatch.end[0] = mymatch.index;
mymatch.finish(stream);
stream.move(mymatch.toString().length());
offset += mymatch.toString().length();
buffer = mymatch.substituteInto(replace);
bufpos = 1;
// This is prone to infinite loops if replace string turns out empty.
if (buffer.length() > 0)
{
return buffer.charAt(0);
}
}
char ch = stream.charAt(0);
if (ch == CharIndexed.OUT_OF_BOUNDS) return -1;
stream.move(1);
offset++;
return ch;
}
/**
* Returns false. REFilterInputStream does not support mark() and
* reset() methods.
*/
public boolean markSupported()
{
return false;
}
/** Reads from the stream into the provided array. */
public int read(byte[] b, int off, int len)
{
int i;
int ok = 0;
while (len-- > 0)
{
i = read();
if (i == -1) return (ok == 0) ? -1 : ok;
b[off++] = (byte)i;
ok++;
}
return ok;
}
/** Reads from the stream into the provided array. */
public int read(byte[] b)
{
return read(b, 0, b.length);
}
}

View File

@ -0,0 +1,128 @@
/*
* gnu/regexp/REFilterReader.java
* Copyright (C) 2001 Lee Sau Dan
* Based on gnu.regexp.REFilterInputStream by Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
import java.io.FilterReader;
import java.io.Reader;
/**
* Replaces instances of a given RE with replacement text.
*
* @author <A HREF="http://www.csis.hku.hk/~sdlee/">Lee Sau Dan</A>
* @since gnu.regexp 1.1.0
*/
public class REFilterReader extends FilterReader
{
private RE expr;
private String replace;
private String buffer;
private int bufpos;
private int offset;
private CharIndexedReader stream;
/**
* Creates an REFilterReader. When reading from this stream,
* occurrences of patterns matching the supplied regular expression
* will be replaced with the supplied replacement text (the
* metacharacters $0 through $9 may be used to refer to the full
* match or subexpression matches.
*
* @param stream The Reader to be filtered.
* @param expr The regular expression to search for.
* @param replace The text pattern to replace matches with.
*/
public REFilterReader(Reader stream, RE expr, String replace)
{
super(stream);
this.stream = new CharIndexedReader(stream, 0);
this.expr = expr;
this.replace = replace;
}
/**
* Reads the next character from the stream per the general contract of
* Reader.read(). Returns -1 on error or end of stream.
*/
public int read()
{
// If we have buffered replace data, use it.
if ((buffer != null) && (bufpos < buffer.length()))
{
return (int)buffer.charAt(bufpos++);
}
// check if input is at a valid position
if (!stream.isValid()) return -1;
REMatch mymatch = new REMatch(expr.getNumSubs(), offset, 0);
if (expr.match(stream, mymatch))
{
mymatch.end[0] = mymatch.index;
mymatch.finish(stream);
stream.move(mymatch.toString().length());
offset += mymatch.toString().length();
buffer = mymatch.substituteInto(replace);
bufpos = 1;
if (buffer.length() > 0)
{
return buffer.charAt(0);
}
}
char ch = stream.charAt(0);
if (ch == CharIndexed.OUT_OF_BOUNDS) return -1;
stream.move(1);
offset++;
return ch;
}
/**
* Returns false. REFilterReader does not support mark() and
* reset() methods.
*/
public boolean markSupported()
{
return false;
}
/** Reads from the stream into the provided array. */
public int read(char[] b, int off, int len)
{
int i;
int ok = 0;
while (len-- > 0)
{
i = read();
if (i == -1) return (ok == 0) ? -1 : ok;
b[off++] = (char)i;
ok++;
}
return ok;
}
/** Reads from the stream into the provided array. */
public int read(char[] b)
{
return read(b, 0, b.length);
}
}

271
src/gnu/regexp/REMatch.java Normal file
View File

@ -0,0 +1,271 @@
/*
* gnu/regexp/REMatch.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
import java.io.Serializable;
/**
* An instance of this class represents a match
* completed by a gnu.regexp matching function. It can be used
* to obtain relevant information about the location of a match
* or submatch.
*
* @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
*/
public final class REMatch implements Serializable, Cloneable
{
private String matchedText;
// These variables are package scope for fast access within the engine
int eflags; // execution flags this match was made using
// Offset in source text where match was tried. This is zero-based;
// the actual position in the source text is given by (offset + anchor).
int offset;
// Anchor position refers to the index into the source input
// at which the matching operation began.
// This is also useful for the ANCHORINDEX option.
int anchor;
// Package scope; used by RE.
int index; // used while matching to mark current match position in input
int[] start; // start positions (relative to offset) for each (sub)exp.
int[] end; // end positions for the same
REMatch next; // other possibility (to avoid having to use arrays)
public Object clone()
{
try
{
REMatch copy = (REMatch)super.clone();
copy.next = null;
copy.start = (int[])start.clone();
copy.end = (int[])end.clone();
return copy;
}
catch (CloneNotSupportedException e)
{
throw new Error(); // doesn't happen
}
}
void assignFrom(REMatch other)
{
start = other.start;
end = other.end;
index = other.index;
// need to deep clone?
next = other.next;
}
REMatch(int subs, int anchor, int eflags)
{
start = new int[subs + 1];
end = new int[subs + 1];
this.anchor = anchor;
this.eflags = eflags;
clear(anchor);
}
void finish(CharIndexed text)
{
start[0] = 0;
StringBuffer sb = new StringBuffer();
int i;
for (i = 0; i < end[0]; i++)
sb.append(text.charAt(i));
matchedText = sb.toString();
for (i = 0; i < start.length; i++)
{
// If any subexpressions didn't terminate, they don't count
// TODO check if this code ever gets hit
if ((start[i] == -1) ^ (end[i] == -1))
{
start[i] = -1;
end[i] = -1;
}
}
next = null; // cut off alternates
}
/** Clears the current match and moves the offset to the new index. */
void clear(int index)
{
offset = index;
this.index = 0;
for (int i = 0; i < start.length; i++)
{
start[i] = end[i] = -1;
}
next = null; // cut off alternates
}
/**
* Returns the string matching the pattern. This makes it convenient
* to write code like the following:
* <P>
* <code>
* REMatch myMatch = myExpression.getMatch(myString);<br>
* if (myMatch != null) System.out.println("Regexp found: "+myMatch);
* </code>
*/
public String toString()
{
return matchedText;
}
/**
* Returns the index within the input text where the match in its entirety
* began.
*/
public int getStartIndex()
{
return offset + start[0];
}
/**
* Returns the index within the input string where the match in
* its entirety ends. The return value is the next position after
* the end of the string; therefore, a match created by the
* following call:
*
* <P>
* <code>REMatch myMatch = myExpression.getMatch(myString);</code>
* <P>
* can be viewed (given that myMatch is not null) by creating
* <P>
* <code>String theMatch = myString.substring(myMatch.getStartIndex(),
* myMatch.getEndIndex());</code>
* <P>
* But you can save yourself that work, since the <code>toString()</code>
* method (above) does exactly that for you.
*/
public int getEndIndex()
{
return offset + end[0];
}
/**
* Returns the string matching the given subexpression. The subexpressions
* are indexed starting with one, not zero. That is, the subexpression
* identified by the first set of parentheses in a regular expression
* could be retrieved from an REMatch by calling match.toString(1).
*
* @param sub Index of the subexpression.
*/
public String toString(int sub)
{
if ((sub >= start.length) || (start[sub] == -1)) return "";
return (matchedText.substring(start[sub], end[sub]));
}
/**
* Returns the index within the input string used to generate this match
* where subexpression number <i>sub</i> begins, or <code>-1</code> if
* the subexpression does not exist. The initial position is zero.
*
* @param sub Subexpression index
* @deprecated Use getStartIndex(int) instead.
*/
public int getSubStartIndex(int sub)
{
if (sub >= start.length) return -1;
int x = start[sub];
return (x == -1) ? x : offset + x;
}
/**
* Returns the index within the input string used to generate this match
* where subexpression number <i>sub</i> begins, or <code>-1</code> if
* the subexpression does not exist. The initial position is zero.
*
* @param sub Subexpression index
* @since gnu.regexp 1.1.0
*/
public int getStartIndex(int sub)
{
if (sub >= start.length) return -1;
int x = start[sub];
return (x == -1) ? x : offset + x;
}
/**
* Returns the index within the input string used to generate this match
* where subexpression number <i>sub</i> ends, or <code>-1</code> if
* the subexpression does not exist. The initial position is zero.
*
* @param sub Subexpression index
* @deprecated Use getEndIndex(int) instead
*/
public int getSubEndIndex(int sub)
{
if (sub >= start.length) return -1;
int x = end[sub];
return (x == -1) ? x : offset + x;
}
/**
* Returns the index within the input string used to generate this match
* where subexpression number <i>sub</i> ends, or <code>-1</code> if
* the subexpression does not exist. The initial position is zero.
*
* @param sub Subexpression index
*/
public int getEndIndex(int sub)
{
if (sub >= start.length) return -1;
int x = end[sub];
return (x == -1) ? x : offset + x;
}
/**
* Substitute the results of this match to create a new string.
* This is patterned after PERL, so the tokens to watch out for are
* <code>$0</code> through <code>$9</code>. <code>$0</code> matches
* the full substring matched; <code>$<i>n</i></code> matches
* subexpression number <i>n</i>.
*
* @param input A string consisting of literals and <code>$<i>n</i></code> tokens.
*/
public String substituteInto(String input)
{
// a la Perl, $0 is whole thing, $1 - $9 are subexpressions
StringBuffer output = new StringBuffer();
int pos;
for (pos = 0; pos < input.length() - 1; pos++)
{
if ((input.charAt(pos) == '\\') && (Character.isDigit(input.charAt(pos + 1))))
{
int val = Character.digit(input.charAt(++pos), 10);
if (val < start.length)
{
output.append(toString(val));
}
}
else
output.append(input.charAt(pos));
}
if (pos < input.length()) output.append(input.charAt(pos));
return output.toString();
}
}

View File

@ -0,0 +1,129 @@
/*
* gnu/regexp/REMatchEnumeration.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
import java.io.Serializable;
import java.util.Enumeration;
import java.util.NoSuchElementException;
/**
* An REMatchEnumeration enumerates regular expression matches over a
* given input text. You obtain a reference to an enumeration using
* the <code>getMatchEnumeration()</code> methods on an instance of
* RE.
*
* <P>
*
* REMatchEnumeration does lazy computation; that is, it will not
* search for a match until it needs to. If you'd rather just get all
* the matches at once in a big array, use the
* <code>getAllMatches()</code> methods on RE. However, using an
* enumeration can help speed performance when the entire text does
* not need to be searched immediately.
*
* <P>
*
* The enumerated type is especially useful when searching on a Reader
* or InputStream, because the InputStream read position cannot be
* guaranteed after calling <code>getMatch()</code> (see the
* description of that method for an explanation of why). Enumeration
* also saves a lot of overhead required when calling
* <code>getMatch()</code> multiple times.
*
* @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
*/
public class REMatchEnumeration implements Enumeration, Serializable
{
private static final int YES = 1;
private static final int MAYBE = 0;
private static final int NO = -1;
private int more;
private REMatch match;
private RE expr;
private CharIndexed input;
private int eflags;
private int index;
// Package scope constructor is used by RE.getMatchEnumeration()
REMatchEnumeration(RE expr, CharIndexed input, int index, int eflags)
{
more = MAYBE;
this.expr = expr;
this.input = input;
this.index = index;
this.eflags = eflags;
}
/** Returns true if there are more matches in the input text. */
public boolean hasMoreElements()
{
return hasMoreMatches(null);
}
/** Returns true if there are more matches in the input text. */
public boolean hasMoreMatches()
{
return hasMoreMatches(null);
}
/** Returns true if there are more matches in the input text.
* Saves the text leading up to the match (or to the end of the input)
* in the specified buffer.
*/
public boolean hasMoreMatches(StringBuffer buffer)
{
if (more == MAYBE)
{
match = expr.getMatchImpl(input, index, eflags, buffer);
if (match != null)
{
input.move((match.end[0] > 0) ? match.end[0] : 1);
index = (match.end[0] > 0) ? match.end[0] + match.offset : index + 1;
more = YES;
}
else
more = NO;
}
return (more == YES);
}
/** Returns the next match in the input text. */
public Object nextElement() throws NoSuchElementException
{
return nextMatch();
}
/**
* Returns the next match in the input text. This method is provided
* for convenience to avoid having to explicitly cast the return value
* to class REMatch.
*/
public REMatch nextMatch() throws NoSuchElementException
{
if (hasMoreElements())
{
more = (input.isValid()) ? MAYBE : NO;
return match;
}
throw new NoSuchElementException();
}
}

View File

@ -0,0 +1,502 @@
/*
* gnu/regexp/RESyntax.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
import java.io.Serializable;
import java.util.BitSet;
/**
* An RESyntax specifies the way a regular expression will be compiled.
* This class provides a number of predefined useful constants for
* emulating popular regular expression syntaxes. Additionally the
* user may construct his or her own syntax, using any combination of the
* syntax bit constants. The syntax is an optional argument to any of the
* matching methods on class RE.
*
* @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
*/
public final class RESyntax implements Serializable
{
static final String DEFAULT_LINE_SEPARATOR = System.getProperty("line.separator");
private static final String SYNTAX_IS_FINAL = RE.getLocalizedMessage("syntax.final");
private BitSet bits;
// true for the constant defined syntaxes
private boolean isFinal = false;
private String lineSeparator = DEFAULT_LINE_SEPARATOR;
// Values for constants are bit indexes
/**
* Syntax bit. Backslash is an escape character in lists.
*/
public static final int RE_BACKSLASH_ESCAPE_IN_LISTS = 0;
/**
* Syntax bit. Use \? instead of ? and \+ instead of +.
*/
public static final int RE_BK_PLUS_QM = 1;
/**
* Syntax bit. POSIX character classes ([:...:]) in lists are allowed.
*/
public static final int RE_CHAR_CLASSES = 2;
/**
* Syntax bit. ^ and $ are special everywhere.
* <B>Not implemented.</B>
*/
public static final int RE_CONTEXT_INDEP_ANCHORS = 3;
/**
* Syntax bit. Repetition operators are only special in valid positions.
* <B>Not implemented.</B>
*/
public static final int RE_CONTEXT_INDEP_OPS = 4;
/**
* Syntax bit. Repetition and alternation operators are invalid
* at start and end of pattern and other places.
* <B>Not implemented</B>.
*/
public static final int RE_CONTEXT_INVALID_OPS = 5;
/**
* Syntax bit. Match-any-character operator (.) matches a newline.
*/
public static final int RE_DOT_NEWLINE = 6;
/**
* Syntax bit. Match-any-character operator (.) does not match a null.
*/
public static final int RE_DOT_NOT_NULL = 7;
/**
* Syntax bit. Intervals ({x}, {x,}, {x,y}) are allowed.
*/
public static final int RE_INTERVALS = 8;
/**
* Syntax bit. No alternation (|), match one-or-more (+), or
* match zero-or-one (?) operators.
*/
public static final int RE_LIMITED_OPS = 9;
/**
* Syntax bit. Newline is an alternation operator.
*/
public static final int RE_NEWLINE_ALT = 10; // impl.
/**
* Syntax bit. Intervals use { } instead of \{ \}
*/
public static final int RE_NO_BK_BRACES = 11;
/**
* Syntax bit. Grouping uses ( ) instead of \( \).
*/
public static final int RE_NO_BK_PARENS = 12;
/**
* Syntax bit. Backreferences not allowed.
*/
public static final int RE_NO_BK_REFS = 13;
/**
* Syntax bit. Alternation uses | instead of \|
*/
public static final int RE_NO_BK_VBAR = 14;
/**
* Syntax bit. <B>Not implemented</B>.
*/
public static final int RE_NO_EMPTY_RANGES = 15;
/**
* Syntax bit. An unmatched right parenthesis (')' or '\)', depending
* on RE_NO_BK_PARENS) will throw an exception when compiling.
*/
public static final int RE_UNMATCHED_RIGHT_PAREN_ORD = 16;
/**
* Syntax bit. <B>Not implemented.</B>
*/
public static final int RE_HAT_LISTS_NOT_NEWLINE = 17;
/**
* Syntax bit. Stingy matching is allowed (+?, *?, ??, {x,y}?).
*/
public static final int RE_STINGY_OPS = 18;
/**
* Syntax bit. Allow character class escapes (\d, \D, \s, \S, \w, \W).
*/
public static final int RE_CHAR_CLASS_ESCAPES = 19;
/**
* Syntax bit. Allow use of (?:xxx) grouping (subexpression is not saved).
*/
public static final int RE_PURE_GROUPING = 20;
/**
* Syntax bit. Allow use of (?=xxx) and (?!xxx) apply the subexpression
* to the text following the current position without consuming that text.
*/
public static final int RE_LOOKAHEAD = 21;
/**
* Syntax bit. Allow beginning- and end-of-string anchors (\A, \Z).
*/
public static final int RE_STRING_ANCHORS = 22;
/**
* Syntax bit. Allow embedded comments, (?#comment), as in Perl5.
*/
public static final int RE_COMMENTS = 23;
/**
* Syntax bit. Allow character class escapes within lists, as in Perl5.
*/
public static final int RE_CHAR_CLASS_ESC_IN_LISTS = 24;
private static final int BIT_TOTAL = 25;
/**
* Predefined syntax.
* Emulates regular expression support in the awk utility.
*/
public static final RESyntax RE_SYNTAX_AWK;
/**
* Predefined syntax.
* Emulates regular expression support in the ed utility.
*/
public static final RESyntax RE_SYNTAX_ED;
/**
* Predefined syntax.
* Emulates regular expression support in the egrep utility.
*/
public static final RESyntax RE_SYNTAX_EGREP;
/**
* Predefined syntax.
* Emulates regular expression support in the GNU Emacs editor.
*/
public static final RESyntax RE_SYNTAX_EMACS;
/**
* Predefined syntax.
* Emulates regular expression support in the grep utility.
*/
public static final RESyntax RE_SYNTAX_GREP;
/**
* Predefined syntax.
* Emulates regular expression support in the POSIX awk specification.
*/
public static final RESyntax RE_SYNTAX_POSIX_AWK;
/**
* Predefined syntax.
* Emulates POSIX basic regular expression support.
*/
public static final RESyntax RE_SYNTAX_POSIX_BASIC;
/**
* Predefined syntax.
* Emulates regular expression support in the POSIX egrep specification.
*/
public static final RESyntax RE_SYNTAX_POSIX_EGREP;
/**
* Predefined syntax.
* Emulates POSIX extended regular expression support.
*/
public static final RESyntax RE_SYNTAX_POSIX_EXTENDED;
/**
* Predefined syntax.
* Emulates POSIX basic minimal regular expressions.
*/
public static final RESyntax RE_SYNTAX_POSIX_MINIMAL_BASIC;
/**
* Predefined syntax.
* Emulates POSIX extended minimal regular expressions.
*/
public static final RESyntax RE_SYNTAX_POSIX_MINIMAL_EXTENDED;
/**
* Predefined syntax.
* Emulates regular expression support in the sed utility.
*/
public static final RESyntax RE_SYNTAX_SED;
/**
* Predefined syntax.
* Emulates regular expression support in Larry Wall's perl, version 4,
*/
public static final RESyntax RE_SYNTAX_PERL4;
/**
* Predefined syntax.
* Emulates regular expression support in Larry Wall's perl, version 4,
* using single line mode (/s modifier).
*/
public static final RESyntax RE_SYNTAX_PERL4_S; // single line mode (/s)
/**
* Predefined syntax.
* Emulates regular expression support in Larry Wall's perl, version 5.
*/
public static final RESyntax RE_SYNTAX_PERL5;
/**
* Predefined syntax.
* Emulates regular expression support in Larry Wall's perl, version 5,
* using single line mode (/s modifier).
*/
public static final RESyntax RE_SYNTAX_PERL5_S;
static
{
// Define syntaxes
RE_SYNTAX_EMACS = new RESyntax().makeFinal();
RESyntax RE_SYNTAX_POSIX_COMMON = new RESyntax()
.set(RE_CHAR_CLASSES)
.set(RE_DOT_NEWLINE)
.set(RE_DOT_NOT_NULL)
.set(RE_INTERVALS)
.set(RE_NO_EMPTY_RANGES)
.makeFinal();
RE_SYNTAX_POSIX_BASIC = new RESyntax(RE_SYNTAX_POSIX_COMMON)
.set(RE_BK_PLUS_QM)
.makeFinal();
RE_SYNTAX_POSIX_EXTENDED = new RESyntax(RE_SYNTAX_POSIX_COMMON)
.set(RE_CONTEXT_INDEP_ANCHORS)
.set(RE_CONTEXT_INDEP_OPS)
.set(RE_NO_BK_BRACES)
.set(RE_NO_BK_PARENS)
.set(RE_NO_BK_VBAR)
.set(RE_UNMATCHED_RIGHT_PAREN_ORD)
.makeFinal();
RE_SYNTAX_AWK = new RESyntax()
.set(RE_BACKSLASH_ESCAPE_IN_LISTS)
.set(RE_DOT_NOT_NULL)
.set(RE_NO_BK_PARENS)
.set(RE_NO_BK_REFS)
.set(RE_NO_BK_VBAR)
.set(RE_NO_EMPTY_RANGES)
.set(RE_UNMATCHED_RIGHT_PAREN_ORD)
.makeFinal();
RE_SYNTAX_POSIX_AWK = new RESyntax(RE_SYNTAX_POSIX_EXTENDED)
.set(RE_BACKSLASH_ESCAPE_IN_LISTS)
.makeFinal();
RE_SYNTAX_GREP = new RESyntax()
.set(RE_BK_PLUS_QM)
.set(RE_CHAR_CLASSES)
.set(RE_HAT_LISTS_NOT_NEWLINE)
.set(RE_INTERVALS)
.set(RE_NEWLINE_ALT)
.makeFinal();
RE_SYNTAX_EGREP = new RESyntax()
.set(RE_CHAR_CLASSES)
.set(RE_CONTEXT_INDEP_ANCHORS)
.set(RE_CONTEXT_INDEP_OPS)
.set(RE_HAT_LISTS_NOT_NEWLINE)
.set(RE_NEWLINE_ALT)
.set(RE_NO_BK_PARENS)
.set(RE_NO_BK_VBAR)
.makeFinal();
RE_SYNTAX_POSIX_EGREP = new RESyntax(RE_SYNTAX_EGREP)
.set(RE_INTERVALS)
.set(RE_NO_BK_BRACES)
.makeFinal();
/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
RE_SYNTAX_ED = new RESyntax(RE_SYNTAX_POSIX_BASIC)
.makeFinal();
RE_SYNTAX_SED = new RESyntax(RE_SYNTAX_POSIX_BASIC)
.makeFinal();
RE_SYNTAX_POSIX_MINIMAL_BASIC = new RESyntax(RE_SYNTAX_POSIX_COMMON)
.set(RE_LIMITED_OPS)
.makeFinal();
/* Differs from RE_SYNTAX_POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS
replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added. */
RE_SYNTAX_POSIX_MINIMAL_EXTENDED = new RESyntax(RE_SYNTAX_POSIX_COMMON)
.set(RE_CONTEXT_INDEP_ANCHORS)
.set(RE_CONTEXT_INVALID_OPS)
.set(RE_NO_BK_BRACES)
.set(RE_NO_BK_PARENS)
.set(RE_NO_BK_REFS)
.set(RE_NO_BK_VBAR)
.set(RE_UNMATCHED_RIGHT_PAREN_ORD)
.makeFinal();
/* There is no official Perl spec, but here's a "best guess" */
RE_SYNTAX_PERL4 = new RESyntax()
.set(RE_BACKSLASH_ESCAPE_IN_LISTS)
.set(RE_CONTEXT_INDEP_ANCHORS)
.set(RE_CONTEXT_INDEP_OPS)// except for '{', apparently
.set(RE_INTERVALS)
.set(RE_NO_BK_BRACES)
.set(RE_NO_BK_PARENS)
.set(RE_NO_BK_VBAR)
.set(RE_NO_EMPTY_RANGES)
.set(RE_CHAR_CLASS_ESCAPES)// \d,\D,\w,\W,\s,\S
.makeFinal();
RE_SYNTAX_PERL4_S = new RESyntax(RE_SYNTAX_PERL4)
.set(RE_DOT_NEWLINE)
.makeFinal();
RE_SYNTAX_PERL5 = new RESyntax(RE_SYNTAX_PERL4)
.set(RE_PURE_GROUPING)// (?:)
.set(RE_STINGY_OPS)// *?,??,+?,{}?
.set(RE_LOOKAHEAD)// (?=)(?!)
.set(RE_STRING_ANCHORS)// \A,\Z
.set(RE_CHAR_CLASS_ESC_IN_LISTS)// \d,\D,\w,\W,\s,\S within []
.set(RE_COMMENTS)// (?#)
.makeFinal();
RE_SYNTAX_PERL5_S = new RESyntax(RE_SYNTAX_PERL5)
.set(RE_DOT_NEWLINE)
.makeFinal();
}
/**
* Construct a new syntax object with all bits turned off.
* This is equivalent to RE_SYNTAX_EMACS.
*/
public RESyntax()
{
bits = new BitSet(BIT_TOTAL);
}
/**
* Called internally when constructing predefined syntaxes
* so their interpretation cannot vary. Conceivably useful
* for your syntaxes as well. Causes IllegalAccessError to
* be thrown if any attempt to modify the syntax is made.
*
* @return this object for convenient chaining
*/
public RESyntax makeFinal()
{
isFinal = true;
return this;
}
/**
* Construct a new syntax object with all bits set the same
* as the other syntax.
*/
public RESyntax(RESyntax other)
{
bits = (BitSet)other.bits.clone();
}
/**
* Check if a given bit is set in this syntax.
*/
public boolean get(int index)
{
return bits.get(index);
}
/**
* Set a given bit in this syntax.
*
* @param index the constant (RESyntax.RE_xxx) bit to set.
* @return a reference to this object for easy chaining.
*/
public RESyntax set(int index)
{
if (isFinal) throw new IllegalAccessError(SYNTAX_IS_FINAL);
bits.set(index);
return this;
}
/**
* Clear a given bit in this syntax.
*
* @param index the constant (RESyntax.RE_xxx) bit to clear.
* @return a reference to this object for easy chaining.
*/
public RESyntax clear(int index)
{
if (isFinal) throw new IllegalAccessError(SYNTAX_IS_FINAL);
bits.clear(index);
return this;
}
/**
* Changes the line separator string for regular expressions
* created using this RESyntax. The default separator is the
* value returned by the system property "line.separator", which
* should be correct when reading platform-specific files from a
* filesystem. However, many programs may collect input from
* sources where the line separator is differently specified (for
* example, in the applet environment, the text box widget
* interprets line breaks as single-character newlines,
* regardless of the host platform.
*
* Note that setting the line separator to a character or
* characters that have specific meaning within the current syntax
* can cause unexpected chronosynclastic infundibula.
*
* @return this object for convenient chaining
*/
public RESyntax setLineSeparator(String aSeparator)
{
if (isFinal) throw new IllegalAccessError(SYNTAX_IS_FINAL);
lineSeparator = aSeparator;
return this;
}
/**
* Returns the currently active line separator string. The default
* is the platform-dependent system property "line.separator".
*/
public String getLineSeparator()
{
return lineSeparator;
}
}

View File

@ -0,0 +1,82 @@
/*
* gnu/regexp/REToken.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
import java.io.Serializable;
abstract class REToken implements Serializable
{
protected REToken next = null;
protected REToken uncle = null;
protected int subIndex;
protected REToken(int subIndex)
{
this.subIndex = subIndex;
}
int getMinimumLength()
{
return 0;
}
void setUncle(REToken anUncle)
{
uncle = anUncle;
}
/** Returns true if the match succeeded, false if it failed. */
abstract boolean match(CharIndexed input, REMatch mymatch);
/** Returns true if the rest of the tokens match, false if they fail. */
protected boolean next(CharIndexed input, REMatch mymatch)
{
if (next == null)
{
if (uncle == null)
{
return true;
}
else
{
return uncle.match(input, mymatch);
}
}
else
{
return next.match(input, mymatch);
}
}
boolean chain(REToken token)
{
next = token;
return true; // Token was accepted
}
abstract void dump(StringBuffer os);
void dumpAll(StringBuffer os)
{
dump(os);
if (next != null) next.dumpAll(os);
}
}

View File

@ -0,0 +1,60 @@
/*
* gnu/regexp/RETokenAny.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
final class RETokenAny extends REToken
{
/** True if '.' can match a newline (RE_DOT_NEWLINE) */
private boolean newline;
/** True if '.' can't match a null (RE_DOT_NOT_NULL) */
private boolean matchNull;
RETokenAny(int subIndex, boolean newline, boolean matchNull)
{
super(subIndex);
this.newline = newline;
this.matchNull = matchNull;
}
int getMinimumLength()
{
return 1;
}
boolean match(CharIndexed input, REMatch mymatch)
{
char ch = input.charAt(mymatch.index);
if ((ch == CharIndexed.OUT_OF_BOUNDS)
|| (!newline && (ch == '\n'))
|| (matchNull && (ch == 0)))
{
return false;
}
++mymatch.index;
return next(input, mymatch);
}
void dump(StringBuffer os)
{
os.append('.');
}
}

View File

@ -0,0 +1,59 @@
/*
* gnu/regexp/RETokenBackRef.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
final class RETokenBackRef extends REToken
{
private int num;
private boolean insens;
RETokenBackRef(int subIndex, int num, boolean insens)
{
super(subIndex);
this.num = num;
this.insens = insens;
}
// should implement getMinimumLength() -- any ideas?
boolean match(CharIndexed input, REMatch mymatch)
{
int b,e;
b = mymatch.start[num];
e = mymatch.end[num];
if ((b == -1) || (e == -1)) return false; // this shouldn't happen, but...
for (int i = b; i < e; i++)
{
if (input.charAt(mymatch.index + i - b) != input.charAt(i))
{
return false;
}
}
mymatch.index += e - b;
return next(input, mymatch);
}
void dump(StringBuffer os)
{
os.append('\\').append(num);
}
}

View File

@ -0,0 +1,83 @@
/*
* gnu/regexp/RETokenChar.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
final class RETokenChar extends REToken
{
private char[] ch;
private boolean insens;
RETokenChar(int subIndex, char c, boolean ins)
{
super(subIndex);
ch = new char[1];
ch[0] = (insens = ins) ? Character.toLowerCase(c) : c;
}
int getMinimumLength()
{
return ch.length;
}
boolean match(CharIndexed input, REMatch mymatch)
{
int z = ch.length;
char c;
for (int i = 0; i < z; i++)
{
c = input.charAt(mymatch.index + i);
if (((insens) ? Character.toLowerCase(c) : c) != ch[i])
{
return false;
}
}
mymatch.index += z;
return next(input, mymatch);
}
// Overrides REToken.chain() to optimize for strings
boolean chain(REToken next)
{
if (next instanceof RETokenChar)
{
RETokenChar cnext = (RETokenChar)next;
// assume for now that next can only be one character
int newsize = ch.length + cnext.ch.length;
char[] chTemp = new char[newsize];
System.arraycopy(ch, 0, chTemp, 0, ch.length);
System.arraycopy(cnext.ch, 0, chTemp, ch.length, cnext.ch.length);
ch = chTemp;
return false;
}
else
return super.chain(next);
}
void dump(StringBuffer os)
{
os.append(ch);
}
}

View File

@ -0,0 +1,62 @@
/*
* gnu/regexp/RETokenEnd.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
final class RETokenEnd extends REToken
{
/**
* Indicates whether this token should match on a line break.
*/
private String newline;
RETokenEnd(int subIndex, String newline)
{
super(subIndex);
this.newline = newline;
}
boolean match(CharIndexed input, REMatch mymatch)
{
char ch = input.charAt(mymatch.index);
if (ch == CharIndexed.OUT_OF_BOUNDS)
return ((mymatch.eflags & RE.REG_NOTEOL) > 0) ?
false : next(input, mymatch);
if (newline != null)
{
char z;
int i = 0; // position in newline
do
{
z = newline.charAt(i);
if (ch != z) return false;
++i;
ch = input.charAt(mymatch.index + i);
}
while (i < newline.length());
return next(input, mymatch);
}
return false;
}
void dump(StringBuffer os)
{
os.append('$');
}
}

View File

@ -0,0 +1,39 @@
/*
* gnu/regexp/RETokenEndSub.java
* Copyright (C) 2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
final class RETokenEndSub extends REToken
{
RETokenEndSub(int subIndex)
{
super(subIndex);
}
boolean match(CharIndexed input, REMatch mymatch)
{
mymatch.end[subIndex] = mymatch.index;
return next(input, mymatch);
}
void dump(StringBuffer os)
{
// handled by RE
}
}

View File

@ -0,0 +1,73 @@
/*
* gnu/regexp/RETokenOneOf.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
/**
* @since gnu.regexp 1.1.3
* @author Shashank Bapat
*/
final class RETokenLookAhead extends REToken
{
REToken re;
boolean negative;
RETokenLookAhead(REToken re, boolean negative) throws REException
{
super(0);
this.re = re;
this.negative = negative;
}
boolean match(CharIndexed input, REMatch mymatch)
{
REMatch trymatch = (REMatch)mymatch.clone();
REMatch trymatch1 = (REMatch)mymatch.clone();
REMatch newMatch = null;
if (re.match(input, trymatch))
{
if (negative) return false;
if (next(input, trymatch1))
newMatch = trymatch1;
}
if (newMatch != null)
{
if (negative) return false;
//else
mymatch.assignFrom(newMatch);
return true;
}
else
{ // no match
if (negative)
return next(input, mymatch);
//else
return false;
}
}
void dump(StringBuffer os)
{
os.append("(?");
os.append(negative ? '!' : '=');
re.dumpAll(os);
os.append(')');
}
}

View File

@ -0,0 +1,136 @@
/*
* gnu/regexp/RETokenOneOf.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
import java.util.Vector;
final class RETokenOneOf extends REToken
{
private Vector options;
private boolean negative;
// This constructor is used for convenience when we know the set beforehand,
// e.g. \d --> new RETokenOneOf("0123456789",false, ..)
// \D --> new RETokenOneOf("0123456789",true, ..)
RETokenOneOf(int subIndex, String optionsStr, boolean negative, boolean insens)
{
super(subIndex);
options = new Vector();
this.negative = negative;
for (int i = 0; i < optionsStr.length(); i++)
options.addElement(new RETokenChar(subIndex, optionsStr.charAt(i), insens));
}
RETokenOneOf(int subIndex, Vector options, boolean negative)
{
super(subIndex);
this.options = options;
this.negative = negative;
}
int getMinimumLength()
{
int min = Integer.MAX_VALUE;
int x;
for (int i = 0; i < options.size(); i++)
{
if ((x = ((REToken)options.elementAt(i)).getMinimumLength()) < min)
min = x;
}
return min;
}
boolean match(CharIndexed input, REMatch mymatch)
{
if (negative && (input.charAt(mymatch.index) == CharIndexed.OUT_OF_BOUNDS))
return false;
REMatch newMatch = null;
REMatch last = null;
REToken tk;
boolean isMatch;
for (int i = 0; i < options.size(); i++)
{
tk = (REToken)options.elementAt(i);
REMatch tryMatch = (REMatch)mymatch.clone();
if (tk.match(input, tryMatch))
{ // match was successful
if (negative) return false;
if (next(input, tryMatch))
{
// Add tryMatch to list of possibilities.
if (last == null)
{
newMatch = tryMatch;
last = tryMatch;
}
else
{
last.next = tryMatch;
last = tryMatch;
}
} // next succeeds
} // is a match
} // try next option
if (newMatch != null)
{
if (negative)
{
return false;
}
else
{
// set contents of mymatch equal to newMatch
// try each one that matched
mymatch.assignFrom(newMatch);
return true;
}
}
else
{
if (negative)
{
++mymatch.index;
return next(input, mymatch);
}
else
{
return false;
}
}
// index+1 works for [^abc] lists, not for generic lookahead (--> index)
}
void dump(StringBuffer os)
{
os.append(negative ? "[^" : "(?:");
for (int i = 0; i < options.size(); i++)
{
if (!negative && (i > 0)) os.append('|');
((REToken)options.elementAt(i)).dumpAll(os);
}
os.append(negative ? ']' : ')');
}
}

View File

@ -0,0 +1,135 @@
/*
* gnu/regexp/RETokenPOSIX.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
final class RETokenPOSIX extends REToken
{
int type;
boolean insens;
boolean negated;
static final int ALNUM = 0;
static final int ALPHA = 1;
static final int BLANK = 2;
static final int CNTRL = 3;
static final int DIGIT = 4;
static final int GRAPH = 5;
static final int LOWER = 6;
static final int PRINT = 7;
static final int PUNCT = 8;
static final int SPACE = 9;
static final int UPPER = 10;
static final int XDIGIT = 11;
// Array indices correspond to constants defined above.
static final String[] s_nameTable = {
"alnum", "alpha", "blank", "cntrl", "digit", "graph", "lower",
"print", "punct", "space", "upper", "xdigit"
};
// The RE constructor uses this to look up the constant for a string
static int intValue(String key)
{
for (int i = 0; i < s_nameTable.length; i++)
{
if (s_nameTable[i].equals(key)) return i;
}
return -1;
}
RETokenPOSIX(int subIndex, int type, boolean insens, boolean negated)
{
super(subIndex);
this.type = type;
this.insens = insens;
this.negated = negated;
}
int getMinimumLength()
{
return 1;
}
boolean match(CharIndexed input, REMatch mymatch)
{
char ch = input.charAt(mymatch.index);
if (ch == CharIndexed.OUT_OF_BOUNDS)
return false;
boolean retval = false;
switch (type)
{
case ALNUM:
// Note that there is some debate over whether '_' should be included
retval = Character.isLetterOrDigit(ch) || (ch == '_');
break;
case ALPHA:
retval = Character.isLetter(ch);
break;
case BLANK:
retval = ((ch == ' ') || (ch == '\t'));
break;
case CNTRL:
retval = Character.isISOControl(ch);
break;
case DIGIT:
retval = Character.isDigit(ch);
break;
case GRAPH:
retval = (!(Character.isWhitespace(ch) || Character.isISOControl(ch)));
break;
case LOWER:
retval = ((insens && Character.isLetter(ch)) || Character.isLowerCase(ch));
break;
case PRINT:
retval = (!(Character.isWhitespace(ch) || Character.isISOControl(ch)))
|| (ch == ' ');
break;
case PUNCT:
// This feels sloppy, especially for non-U.S. locales.
retval = ("`~!@#$%^&*()-_=+[]{}\\|;:'\"/?,.<>".indexOf(ch) != -1);
break;
case SPACE:
retval = Character.isWhitespace(ch);
break;
case UPPER:
retval = ((insens && Character.isLetter(ch)) || Character.isUpperCase(ch));
break;
case XDIGIT:
retval = (Character.isDigit(ch) || ("abcdefABCDEF".indexOf(ch) != -1));
break;
}
if (negated) retval = !retval;
if (retval)
{
++mymatch.index;
return next(input, mymatch);
}
else
return false;
}
void dump(StringBuffer os)
{
if (negated) os.append('^');
os.append("[:" + s_nameTable[type] + ":]");
}
}

View File

@ -0,0 +1,57 @@
/*
* gnu/regexp/RETokenRange.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
final class RETokenRange extends REToken
{
private char lo, hi;
private boolean insens;
RETokenRange(int subIndex, char lo, char hi, boolean ins)
{
super(subIndex);
this.lo = (insens = ins) ? Character.toLowerCase(lo) : lo;
this.hi = ins ? Character.toLowerCase(hi) : hi;
}
int getMinimumLength()
{
return 1;
}
boolean match(CharIndexed input, REMatch mymatch)
{
char c = input.charAt(mymatch.index);
if (c == CharIndexed.OUT_OF_BOUNDS) return false;
if (insens) c = Character.toLowerCase(c);
if ((c >= lo) && (c <= hi))
{
++mymatch.index;
return next(input, mymatch);
}
return false;
}
void dump(StringBuffer os)
{
os.append(lo).append('-').append(hi);
}
}

View File

@ -0,0 +1,241 @@
/*
* gnu/regexp/RETokenRepeated.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
import java.util.Vector;
final class RETokenRepeated extends REToken
{
private REToken token;
private int min,max;
private boolean stingy;
RETokenRepeated(int subIndex, REToken token, int min, int max)
{
super(subIndex);
this.token = token;
this.min = min;
this.max = max;
}
/** Sets the minimal matching mode to true. */
void makeStingy()
{
stingy = true;
}
/** Queries if this token has minimal matching enabled. */
boolean isStingy()
{
return stingy;
}
/**
* The minimum length of a repeated token is the minimum length
* of the token multiplied by the minimum number of times it must
* match.
*/
int getMinimumLength()
{
return (min * token.getMinimumLength());
}
// We do need to save every possible point, but the number of clone()
// invocations here is really a killer for performance on non-stingy
// repeat operators. I'm open to suggestions...
// Hypothetical question: can you have a RE that matches 1 times,
// 3 times, 5 times, but not 2 times or 4 times? Does having
// the subexpression back-reference operator allow that?
boolean match(CharIndexed input, REMatch mymatch)
{
// number of times we've matched so far
int numRepeats = 0;
// Possible positions for the next repeat to match at
REMatch newMatch = mymatch;
REMatch last = null;
REMatch current;
// Add the '0-repeats' index
// positions.elementAt(z) == position [] in input after <<z>> matches
Vector positions = new Vector();
positions.addElement(newMatch);
// Declare variables used in loop
REMatch doables;
REMatch doablesLast;
REMatch recurrent;
do
{
// Check for stingy match for each possibility.
if (stingy && (numRepeats >= min))
{
REMatch result = matchRest(input, newMatch);
if (result != null)
{
mymatch.assignFrom(result);
return true;
}
}
doables = null;
doablesLast = null;
// try next repeat at all possible positions
for (current = newMatch; current != null; current = current.next)
{
recurrent = (REMatch)current.clone();
if (token.match(input, recurrent))
{
// add all items in current to doables array
if (doables == null)
{
doables = recurrent;
doablesLast = recurrent;
}
else
{
// Order these from longest to shortest
// Start by assuming longest (more repeats)
doablesLast.next = recurrent;
}
// Find new doablesLast
while (doablesLast.next != null)
{
doablesLast = doablesLast.next;
}
}
}
// if none of the possibilities worked out, break out of do/while
if (doables == null) break;
// reassign where the next repeat can match
newMatch = doables;
// increment how many repeats we've successfully found
++numRepeats;
positions.addElement(newMatch);
}
while (numRepeats < max);
// If there aren't enough repeats, then fail
if (numRepeats < min) return false;
// We're greedy, but ease off until a true match is found
int posIndex = positions.size();
// At this point we've either got too many or just the right amount.
// See if this numRepeats works with the rest of the regexp.
REMatch allResults = null;
REMatch allResultsLast = null;
REMatch results = null;
while (--posIndex >= min)
{
newMatch = (REMatch)positions.elementAt(posIndex);
results = matchRest(input, newMatch);
if (results != null)
{
if (allResults == null)
{
allResults = results;
allResultsLast = results;
}
else
{
// Order these from longest to shortest
// Start by assuming longest (more repeats)
allResultsLast.next = results;
}
// Find new doablesLast
while (allResultsLast.next != null)
{
allResultsLast = allResultsLast.next;
}
}
// else did not match rest of the tokens, try again on smaller sample
}
if (allResults != null)
{
mymatch.assignFrom(allResults); // does this get all?
return true;
}
// If we fall out, no matches.
return false;
}
private REMatch matchRest(CharIndexed input, final REMatch newMatch)
{
REMatch current, single;
REMatch doneIndex = null;
REMatch doneIndexLast = null;
// Test all possible matches for this number of repeats
for (current = newMatch; current != null; current = current.next)
{
// clone() separates a single match from the chain
single = (REMatch)current.clone();
if (next(input, single))
{
// chain results to doneIndex
if (doneIndex == null)
{
doneIndex = single;
doneIndexLast = single;
}
else
{
doneIndexLast.next = single;
}
// Find new doneIndexLast
while (doneIndexLast.next != null)
{
doneIndexLast = doneIndexLast.next;
}
}
}
return doneIndex;
}
void dump(StringBuffer os)
{
os.append("(?:");
token.dumpAll(os);
os.append(')');
if ((max == Integer.MAX_VALUE) && (min <= 1))
os.append((min == 0) ? '*' : '+');
else if ((min == 0) && (max == 1))
os.append('?');
else
{
os.append('{').append(min);
if (max > min)
{
os.append(',');
if (max != Integer.MAX_VALUE) os.append(max);
}
os.append('}');
}
if (stingy) os.append('?');
}
}

View File

@ -0,0 +1,78 @@
/*
* gnu/regexp/RETokenStart.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
class RETokenStart extends REToken
{
private String newline; // matches after a newline
RETokenStart(int subIndex, String newline)
{
super(subIndex);
this.newline = newline;
}
boolean match(CharIndexed input, REMatch mymatch)
{
// charAt(index-n) may be unknown on a Reader/InputStream. FIXME
// Match after a newline if in multiline mode
if (newline != null)
{
int len = newline.length();
if (mymatch.offset >= len)
{
boolean found = true;
char z;
int i = 0; // position in REToken.newline
char ch = input.charAt(mymatch.index - len);
do
{
z = newline.charAt(i);
if (ch != z)
{
found = false;
break;
}
++i;
ch = input.charAt(mymatch.index - len + i);
}
while (i < len);
if (found) return next(input, mymatch);
}
}
// Don't match at all if REG_NOTBOL is set.
if ((mymatch.eflags & RE.REG_NOTBOL) > 0) return false;
if ((mymatch.eflags & RE.REG_ANCHORINDEX) > 0)
return (mymatch.anchor == mymatch.offset) ?
next(input, mymatch) : false;
else
return ((mymatch.index == 0) && (mymatch.offset == 0)) ?
next(input, mymatch) : false;
}
void dump(StringBuffer os)
{
os.append('^');
}
}

View File

@ -0,0 +1,99 @@
/*
* gnu/regexp/RETokenWordBoundary.java
* Copyright (C) 2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
/**
* Represents a combination lookahead/lookbehind for POSIX [:alnum:].
*/
final class RETokenWordBoundary extends REToken
{
private boolean negated;
private int where;
static final int BEGIN = 1;
static final int END = 2;
RETokenWordBoundary(int subIndex, int where, boolean negated)
{
super(subIndex);
this.where = where;
this.negated = negated;
}
boolean match(CharIndexed input, REMatch mymatch)
{
// Word boundary means input[index-1] was a word character
// and input[index] is not, or input[index] is a word character
// and input[index-1] was not
// In the string "one two three", these positions match:
// |o|n|e| |t|w|o| |t|h|r|e|e|
// ^ ^ ^ ^ ^ ^
boolean after = false; // is current character a letter or digit?
boolean before = false; // is previous character a letter or digit?
char ch;
// TODO: Also check REG_ANCHORINDEX vs. anchor
if (((mymatch.eflags & RE.REG_ANCHORINDEX) != RE.REG_ANCHORINDEX)
|| (mymatch.offset + mymatch.index > mymatch.anchor))
{
if ((ch = input.charAt(mymatch.index - 1)) != CharIndexed.OUT_OF_BOUNDS)
{
before = Character.isLetterOrDigit(ch) || (ch == '_');
}
}
if ((ch = input.charAt(mymatch.index)) != CharIndexed.OUT_OF_BOUNDS)
{
after = Character.isLetterOrDigit(ch) || (ch == '_');
}
// if (before) and (!after), we're at end (\>)
// if (after) and (!before), we're at beginning (\<)
boolean doNext = false;
if ((where & BEGIN) == BEGIN)
{
doNext = after && !before;
}
if ((where & END) == END)
{
doNext ^= before && !after;
}
if (negated) doNext = !doNext;
return (doNext ? next(input, mymatch) : false);
}
void dump(StringBuffer os)
{
if (where == (BEGIN | END))
{
os.append(negated ? "\\B" : "\\b");
}
else if (where == BEGIN)
{
os.append("\\<");
}
else
{
os.append("\\>");
}
}
}

View File

@ -0,0 +1,98 @@
/*
* gnu/regexp/UncheckedRE.java
* Copyright (C) 2001 Wes Biggs
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gnu.regexp;
/**
* UncheckedRE is a subclass of RE that allows programmers an easier means
* of programmatically precompiling regular expressions. It is constructed
* and used in exactly the same manner as an instance of the RE class; the
* only difference is that its constructors do not throw REException.
* Instead, if a syntax error is encountered during construction, a
* RuntimeException will be thrown.
* <P>
* Note that this makes UncheckedRE dangerous if constructed with
* dynamic data. Do not use UncheckedRE unless you are completely sure
* that all input being passed to it contains valid, well-formed
* regular expressions for the syntax specified.
*
* @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
* @see gnu.regexp.RE
* @since gnu.regexp 1.1.4
*/
public final class UncheckedRE extends RE
{
/**
* Constructs a regular expression pattern buffer without any compilation
* flags set, and using the default syntax (RESyntax.RE_SYNTAX_PERL5).
*
* @param pattern A regular expression pattern, in the form of a String,
* StringBuffer or char[]. Other input types will be converted to
* strings using the toString() method.
* @exception RuntimeException The input pattern could not be parsed.
* @exception NullPointerException The pattern was null.
*/
public UncheckedRE(Object pattern)
{
this(pattern, 0, RESyntax.RE_SYNTAX_PERL5);
}
/**
* Constructs a regular expression pattern buffer using the specified
* compilation flags and the default syntax (RESyntax.RE_SYNTAX_PERL5).
*
* @param pattern A regular expression pattern, in the form of a String,
* StringBuffer, or char[]. Other input types will be converted to
* strings using the toString() method.
* @param cflags The logical OR of any combination of the compilation flags in the RE class.
* @exception RuntimeException The input pattern could not be parsed.
* @exception NullPointerException The pattern was null.
*/
public UncheckedRE(Object pattern, int cflags)
{
this(pattern, cflags, RESyntax.RE_SYNTAX_PERL5);
}
/**
* Constructs a regular expression pattern buffer using the specified
* compilation flags and regular expression syntax.
*
* @param pattern A regular expression pattern, in the form of a String,
* StringBuffer, or char[]. Other input types will be converted to
* strings using the toString() method.
* @param cflags The logical OR of any combination of the compilation flags in the RE class.
* @param syntax The type of regular expression syntax to use.
* @exception RuntimeException The input pattern could not be parsed.
* @exception NullPointerException The pattern was null.
*/
public UncheckedRE(Object pattern, int cflags, RESyntax syntax)
{
try
{
initialize(pattern, cflags, syntax, 0, 0);
}
catch (REException e)
{
throw new RuntimeException(e.getMessage());
}
}
}

View File

@ -0,0 +1,149 @@
/*
* gnu/regexp/util/RETest.java
* Copyright (C) 1998-2001 Wes Biggs
*
* This file is in the public domain. However, the gnu.regexp library
* proper is licensed under the terms of the GNU Lesser General Public
* License (see the file COPYING.LIB for details).
*/
package gnu.regexp.util;
import gnu.regexp.*;
/**
* RETest provides a simple way to test regular expressions.
* It runs from the command line using the Java interpreter.
* To use it, enter the following from a command prompt (provided
* that the Java system knows where to find the RETest bytecodes):
* <BR><CODE>java gnu.regexp.util.RETest [regExp] [inputString]</CODE><BR>
* where <i>regExp</i> is a regular expression (you'll probably have
* to escape shell meta-characters) and <i>inputString</i> is the string
* to match against (again, put it in quotes or escape any shell meta-
* characters).
* <P>
* The test function will report the package version number, whether
* the expression matches the input string, what the match it found was,
* and the contents of any subexpressions, if applicable.
* <P>
* You may optionally add a third integer argument which is the number of
* times to repeat the test. When this option is used, RETest will report
* average compile and match times.
*
* @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
* @version 1.01
*/
public class RETest
{
private RETest()
{
}
/**
* Invokes the test function with the command line arguments specified.
* See class description for usage notes.
*
* @param argv
* The command line arguments.
*
* @exception REException
* There was an error compiling or executing the regular expression.
*/
public static void main(String argv[]) throws REException
{
System.out.println("gnu.regexp version " + RE.version());
int numRepeats = 1;
if (argv.length == 3)
numRepeats = Integer.parseInt(argv[2]);
if (argv.length < 2)
{
System.out.println("usage: java gnu.regexp.util.RETest regExp inputString [numRepeats]");
System.exit(1);
}
// Construct the regular expression
RE expression = null;
long begin = System.currentTimeMillis();
for (int rpt = 0; rpt < numRepeats; rpt++)
expression = new RE(argv[0]);
long end = System.currentTimeMillis();
if (numRepeats > 1)
{
System.out.println("Compiling " + numRepeats + " times took " + (end - begin) + " ms");
System.out.println("Average compile time: " + ((end - begin) / numRepeats) + " ms");
}
// Display regular expression
System.out.println(" Input Text: " + argv[1]);
System.out.println("Regular Expression: " + argv[0]);
System.out.println(" Compiled Form: " + expression);
System.out.println(" Minimum Length: " + expression.getMinimumLength());
// Is the input in its entirety a match?
System.out.println(" isMatch() returns: " + expression.isMatch(argv[1]));
REMatch[] matches = expression.getAllMatches(argv[1]);
System.out.println(" getAllMatches(): " + matches.length + " matches");
for (int i = 0; i < matches.length; i++)
{
System.out.println("Match " + i + " (" + matches[i].getStartIndex()
+ "," + matches[i].getEndIndex() + "): "
+ matches[i]);
}
// Get the first match
REMatch match = null;
begin = System.currentTimeMillis();
for (int rpt = 0; rpt < numRepeats; rpt++)
match = expression.getMatch(argv[1]);
end = System.currentTimeMillis();
if (numRepeats > 1)
{
System.out.println("Finding first match " + numRepeats + " times took " + (end - begin) + " ms");
System.out.println("Average match time: " + ((end - begin) / numRepeats) + " ms");
}
if (match == null)
System.out.println("Expression did not find a match.");
else
{
// Report the full match indices
System.out.println("Match found from position "
+ match.getStartIndex() + " to position "
+ match.getEndIndex());
// Take advantage of REMatch.toString() to print match text
System.out.println("Match was: '" + match + "'");
// Report subexpression positions
for (int i = 1; i <= expression.getNumSubs(); i++)
{
if (match.getStartIndex(i) > -1)
{
System.out.println("Subexpression #" + i + ": from position "
+ match.getStartIndex(i) + " to position "
+ match.getEndIndex(i));
// Note how the $n is constructed for substituteInto
System.out.println(match.substituteInto("The subexpression matched this text: '$" + i + "'"));
}
}
}
// Here's a substitute test.
System.out.println("substitute(): " + expression.substitute(argv[1], "<!--$0-->"));
System.out.println("substituteAll(): " + expression.substituteAll(argv[1], "<!--$0-->"));
}
}