Java Doc for Perl5Substitution.java in  » Development » Jakarta-ORO » org » apache » oro » text » regex » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Development » Jakarta ORO » org.apache.oro.text.regex 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.oro.text.regex.StringSubstitution
      org.apache.oro.text.regex.Perl5Substitution

Perl5Substitution
public class Perl5Substitution extends StringSubstitution (Code)
Perl5Substitution implements a Substitution consisting of a literal string, but allowing Perl5 variable interpolation referencing saved groups in a match. This class is intended for use with Util.substitute Util.substitute .

The substitution string may contain variable interpolations referring to the saved parenthesized groups of the search pattern. A variable interpolation is denoted by $1, or $2, or $3, etc. If you want such expressions to be interpreted literally, you should set the numInterpolations parameter to INTERPOLATE_NONE . It is easiest to explain what an interpolated variable does by giving an example:

    Suppose you have the pattern b\d+: and you want to substitute the b's for a's and the colon for a dash in parts of your input matching the pattern. You can do this by changing the pattern to b(\d+): and using the substitution expression a$1-. When a substitution is made, the $1 means "Substitute whatever was matched by the first saved group of the matching pattern." An input of b123: after substitution would yield a result of a123-. But there's a little more to be aware of. If you set the numInterpolations parameter to INTERPOLATE_ALL, then every time a match is found, the interpolation variables are computed relative to that match. But if numInterpolations is set to some positive integer, then only the interpolation variables for the first numInterpolations matches are computed relative to the most recent match. After that, the remaining substitutions have their variable interpolations performed relative to the numInterpolations 'th match. So using the previously mentioned pattern and substitution expression, if you have an input of
    Tank b123: 85  Tank b256: 32  Tank b78: 22
    and use a numInterpolations value of INTERPOLATE_ALL and numSubs value (see Util.substitute Util.substitute ) of SUBSTITUTE_ALL, then your result will be:
    Tank a123- 85  Tank a256- 32  Tank a78- 22
    But if you set numInterpolations to 2 and keep numSubs with a value of SUBSTITUTE_ALL, your result is:
    Tank a123- 85  Tank a256- 32  Tank a256- 22
    Notice how the last substitution uses the same value for $1 as the second substitution.

A final thing to keep in mind is that if you use an interpolation variable that corresponds to a group not contained in the match, then it is interpreted as the empty string. So given the regular expression from the example, and a substitution expression of a$2-, the result of the last sample input would be:

Tank a- 85  Tank a- 32  Tank a- 22
The special substitution $& will interpolate the entire portion of the input matched by the regular expression. $0 will do the same, but it is recommended that it be avoided because the latest versions of Perl use $0 to store the program name rather than duplicate the behavior of $&. Also, the result of substituting $ followed by a non-positive integer is undefined. In order to include a $ in a substitution, it should be escaped with a backslash (e.g., "\\$0").

Perl5 double-quoted string case modification is also supported in the substitution. The following escape sequences are supported:

\\U
make substitution uppercase until end of substitution or \\E
\\u
make next character uppercase
\\L
make substitution uppercase until end of substitution or \\E
\\l
make next character uppercase
\\E
mark the end of the case modification
The double backslashes are shown to remind you that to make a backslash get past Java's string handling and appear as a backslash to the substitution, you must escape the backslash.
version:
   @version@
since:
   1.1
See Also:   Substitution
See Also:   Util
See Also:   Util.substitute
See Also:   Substitution
See Also:   StringSubstitution


Field Summary
final public static  intINTERPOLATE_ALL
     A constant used when creating a Perl5Substitution indicating that interpolation variables should be computed relative to the most recent pattern match.
final public static  intINTERPOLATE_NONE
     A constant used when creating a Perl5Substitution indicating that interpolation variables should be interpreted literally, effectively disabling interpolation.
final static  int_OPCODE_COPY
     A constant declaring opcode for copy operation.
final static  int_OPCODE_ENDCASE_MODE
     A constant declaring opcode for lowercase mode operation.
final static  int_OPCODE_LOWERCASE_CHAR
     A constant declaring opcode for lowercase char operation.
final static  int_OPCODE_LOWERCASE_MODE
     A constant declaring opcode for lowercase mode operation.
final static  int_OPCODE_UPPERCASE_CHAR
     A constant declaring opcode for uppercase char operation.
final static  int_OPCODE_UPPERCASE_MODE
     A constant declaring opcode for lowercase mode operation.
transient  String_lastInterpolation
    
 int_numInterpolations
    
 int[]_subOpcodes
    
 int_subOpcodesCount
    
 char[]_substitutionChars
    

Constructor Summary
public  Perl5Substitution()
     Default constructor initializing substitution to a zero length String and the number of interpolations to Perl5Substitution.INTERPOLATE_ALL .
public  Perl5Substitution(String substitution)
     Creates a Perl5Substitution using the specified substitution and setting the number of interpolations to Perl5Substitution.INTERPOLATE_ALL .
public  Perl5Substitution(String substitution, int numInterpolations)
     Creates a Perl5Substitution using the specified substitution and setting the number of interpolations to the specified value.


Parameters:
  substitution - The string to use as a substitution.
Parameters:
  numInterpolations - If set to INTERPOLATE_NONE, interpolation variables areinterpreted literally and not as references to the savedparenthesized groups of a pattern match.


Method Summary
 void_calcSub(StringBuffer buffer, MatchResult result)
    
 String_finalInterpolatedSub(MatchResult result)
    
public  voidappendSubstitution(StringBuffer appendBuffer, MatchResult match, int substitutionCount, PatternMatcherInput originalInput, PatternMatcher matcher, Pattern pattern)
     Appends the substitution to a buffer containing the original input with substitutions applied for the pattern matches found so far. See Substitution.appendSubstitution Substitution.appendSubstition() for more details regarding the expected behavior of this method.


Parameters:
  appendBuffer - The buffer containing the new string resultingfrom performing substitutions on the original input.
Parameters:
  match - The current match causing a substitution to be made.

public  voidsetSubstitution(String substitution)
     Sets the substitution represented by this Perl5Substitution, also setting the number of interpolations to Perl5Substitution.INTERPOLATE_ALL . You should use this method in order to avoid repeatedly allocating new Perl5Substitutions.
public  voidsetSubstitution(String substitution, int numInterpolations)
     Sets the substitution represented by this Perl5Substitution, also setting the number of interpolations to the specified value. You should use this method in order to avoid repeatedly allocating new Perl5Substitutions.

Field Detail
INTERPOLATE_ALL
final public static int INTERPOLATE_ALL(Code)
A constant used when creating a Perl5Substitution indicating that interpolation variables should be computed relative to the most recent pattern match.



INTERPOLATE_NONE
final public static int INTERPOLATE_NONE(Code)
A constant used when creating a Perl5Substitution indicating that interpolation variables should be interpreted literally, effectively disabling interpolation.



_OPCODE_COPY
final static int _OPCODE_COPY(Code)
A constant declaring opcode for copy operation.



_OPCODE_ENDCASE_MODE
final static int _OPCODE_ENDCASE_MODE(Code)
A constant declaring opcode for lowercase mode operation.



_OPCODE_LOWERCASE_CHAR
final static int _OPCODE_LOWERCASE_CHAR(Code)
A constant declaring opcode for lowercase char operation.



_OPCODE_LOWERCASE_MODE
final static int _OPCODE_LOWERCASE_MODE(Code)
A constant declaring opcode for lowercase mode operation.



_OPCODE_UPPERCASE_CHAR
final static int _OPCODE_UPPERCASE_CHAR(Code)
A constant declaring opcode for uppercase char operation.



_OPCODE_UPPERCASE_MODE
final static int _OPCODE_UPPERCASE_MODE(Code)
A constant declaring opcode for lowercase mode operation.



_lastInterpolation
transient String _lastInterpolation(Code)



_numInterpolations
int _numInterpolations(Code)



_subOpcodes
int[] _subOpcodes(Code)



_subOpcodesCount
int _subOpcodesCount(Code)



_substitutionChars
char[] _substitutionChars(Code)




Constructor Detail
Perl5Substitution
public Perl5Substitution()(Code)
Default constructor initializing substitution to a zero length String and the number of interpolations to Perl5Substitution.INTERPOLATE_ALL .



Perl5Substitution
public Perl5Substitution(String substitution)(Code)
Creates a Perl5Substitution using the specified substitution and setting the number of interpolations to Perl5Substitution.INTERPOLATE_ALL .


Parameters:
  substitution - The string to use as a substitution.




Perl5Substitution
public Perl5Substitution(String substitution, int numInterpolations)(Code)
Creates a Perl5Substitution using the specified substitution and setting the number of interpolations to the specified value.


Parameters:
  substitution - The string to use as a substitution.
Parameters:
  numInterpolations - If set to INTERPOLATE_NONE, interpolation variables areinterpreted literally and not as references to the savedparenthesized groups of a pattern match. If set to INTERPOLATE_ALL , all variable interpolationsare computed relative to the pattern match responsible forthe current substitution. If set to a positive integer,the first numInterpolations substitutions havetheir variable interpolation performed relative to themost recent match, but the remaining substitutions havetheir variable interpolations performed relative to the numInterpolations 'th match.





Method Detail
_calcSub
void _calcSub(StringBuffer buffer, MatchResult result)(Code)



_finalInterpolatedSub
String _finalInterpolatedSub(MatchResult result)(Code)



appendSubstitution
public void appendSubstitution(StringBuffer appendBuffer, MatchResult match, int substitutionCount, PatternMatcherInput originalInput, PatternMatcher matcher, Pattern pattern)(Code)
Appends the substitution to a buffer containing the original input with substitutions applied for the pattern matches found so far. See Substitution.appendSubstitution Substitution.appendSubstition() for more details regarding the expected behavior of this method.


Parameters:
  appendBuffer - The buffer containing the new string resultingfrom performing substitutions on the original input.
Parameters:
  match - The current match causing a substitution to be made.
Parameters:
  substitutionCount - The number of substitutions that have beenperformed so far by Util.substitute.
Parameters:
  originalInput - The original input upon which the substitutions arebeing performed. This is a read-only parameter and is not modified.
Parameters:
  matcher - The PatternMatcher used to find the current match.
Parameters:
  pattern - The Pattern used to find the current match.




setSubstitution
public void setSubstitution(String substitution)(Code)
Sets the substitution represented by this Perl5Substitution, also setting the number of interpolations to Perl5Substitution.INTERPOLATE_ALL . You should use this method in order to avoid repeatedly allocating new Perl5Substitutions. It is recommended that you allocate a single Perl5Substitution and reuse it by using this method when appropriate.


Parameters:
  substitution - The string to use as a substitution.




setSubstitution
public void setSubstitution(String substitution, int numInterpolations)(Code)
Sets the substitution represented by this Perl5Substitution, also setting the number of interpolations to the specified value. You should use this method in order to avoid repeatedly allocating new Perl5Substitutions. It is recommended that you allocate a single Perl5Substitution and reuse it by using this method when appropriate.


Parameters:
  substitution - The string to use as a substitution.
Parameters:
  numInterpolations - If set to INTERPOLATE_NONE, interpolation variables areinterpreted literally and not as references to the savedparenthesized groups of a pattern match. If set to INTERPOLATE_ALL , all variable interpolationsare computed relative to the pattern match responsible forthe current substitution. If set to a positive integer,the first numInterpolations substitutions havetheir variable interpolation performed relative to themost recent match, but the remaining substitutions havetheir variable interpolations performed relative to the numInterpolations 'th match.




Fields inherited from org.apache.oro.text.regex.StringSubstitution
int _subLength(Code)(Java Doc)
String _substitution(Code)(Java Doc)

Methods inherited from org.apache.oro.text.regex.StringSubstitution
public void appendSubstitution(StringBuffer appendBuffer, MatchResult match, int substitutionCount, PatternMatcherInput originalInput, PatternMatcher matcher, Pattern pattern)(Code)(Java Doc)
public String getSubstitution()(Code)(Java Doc)
public void setSubstitution(String substitution)(Code)(Java Doc)
public String toString()(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.