mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
revamp regex support
This commit is contained in:
parent
becceb3eb3
commit
01800b833d
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This file is
|
||||
@ -27,6 +27,12 @@
|
||||
<Get>${this:16}.find()</Get>
|
||||
<Set>${this:16}.setSuccess(${value})</Set>
|
||||
</Property>
|
||||
<Property>
|
||||
<Imports />
|
||||
<Type>System.String</Type>
|
||||
<Name>Value</Name>
|
||||
<Get>${this:16}.getValue()</Get>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events />
|
||||
<Indexers />
|
||||
|
@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This file is
|
||||
|
||||
Copyright 2007,2008,2009,2010 Rustici Software, LLC
|
||||
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
|
||||
-->
|
||||
<Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
|
||||
<Imports>
|
||||
<Import>CS2JNet.System.Text.RegularExpressions.GroupCollection</Import>
|
||||
</Imports>
|
||||
<Java>GroupCollection</Java>
|
||||
<Name>System.Text.RegularExpressions.GroupCollection</Name>
|
||||
<Uses />
|
||||
<Inherits>
|
||||
<Type>System.Collections.ICollection</Type>
|
||||
</Inherits>
|
||||
<Methods />
|
||||
<Properties />
|
||||
<Events />
|
||||
<Indexers>
|
||||
<Indexer>
|
||||
<Imports />
|
||||
<Params>
|
||||
<Param>
|
||||
<Type>System.Int32</Type>
|
||||
<Name>key</Name>
|
||||
</Param>
|
||||
</Params>
|
||||
<Type>System.Text.RegularExpressions.Group</Type>
|
||||
<Get>${this:16}.get(${key})</Get>
|
||||
</Indexer>
|
||||
<Indexer>
|
||||
<Imports />
|
||||
<Warning>CS2J does not yet support Named groups in Regular Expressions</Warning>
|
||||
<Params>
|
||||
<Param>
|
||||
<Type>System.String</Type>
|
||||
<Name>key</Name>
|
||||
</Param>
|
||||
</Params>
|
||||
<Type>System.Text.RegularExpressions.Group</Type>
|
||||
<Get>${this:16}.get(${key})</Get>
|
||||
</Indexer>
|
||||
</Indexers>
|
||||
<Constructors>
|
||||
</Constructors>
|
||||
<Fields />
|
||||
<Casts />
|
||||
<UnaryOps />
|
||||
<BinaryOps />
|
||||
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /><DigestValue>/NAwgdUvZuJRzEnlky9ue6sLWIc=</DigestValue></Reference></SignedInfo><SignatureValue>AVizzM2k9+WSxJekoW45/t/cpEHgGLy2wYWAC9lirjVkTSEkvg+uhCM32tV+6WS4kLUWUPkvAADftndYCs/OI07BLrBG5y/OBFJSs22Aks1P8h972Q33FMPKZfrf7pVR+hhYSQuJPyLxIy0pLBXWOicqlk0jmuojI1oYYGH9+rE=</SignatureValue></Signature></Class>
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This file is
|
||||
@ -9,16 +9,50 @@
|
||||
-->
|
||||
<Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
|
||||
<Imports>
|
||||
<Import>java.util.regex.*</Import>
|
||||
<Import>CS2JNet.System.Text.RegularExpressions.Match</Import>
|
||||
</Imports>
|
||||
<Java>Matcher</Java>
|
||||
<Java>Match</Java>
|
||||
<Name>System.Text.RegularExpressions.Match</Name>
|
||||
<Uses />
|
||||
<Inherits>
|
||||
<Type>System.Text.RegularExpressions.Group</Type>
|
||||
</Inherits>
|
||||
<Methods />
|
||||
<Properties />
|
||||
<Methods>
|
||||
<Method>
|
||||
<Java>${this:16}.nextMatch()</Java>
|
||||
<Params>
|
||||
</Params>
|
||||
<Name>NextMatch</Name>
|
||||
<Return>System.Text.RegularExpressions.Match</Return>
|
||||
</Method>
|
||||
</Methods>
|
||||
<Properties>
|
||||
<Property>
|
||||
<Imports>
|
||||
<Import>CS2JNet.System.Text.RegularExpressions.GroupCollection</Import>
|
||||
</Imports>
|
||||
<Type>System.Text.RegularExpressions.GroupCollection</Type>
|
||||
<Name>Groups</Name>
|
||||
<Get>GroupCollection.mk(${this})</Get>
|
||||
</Property>
|
||||
<Property>
|
||||
<Type>System.Int32</Type>
|
||||
<Name>Length</Name>
|
||||
<Get>${this}.length()</Get>
|
||||
</Property>
|
||||
<Property>
|
||||
<Imports />
|
||||
<Type>System.String</Type>
|
||||
<Name>Value</Name>
|
||||
<Get>${this:16}.getValue()</Get>
|
||||
</Property>
|
||||
<Property>
|
||||
<Imports />
|
||||
<Type>System.Bool</Type>
|
||||
<Name>Success</Name>
|
||||
<Get>${this:16}.getSuccess()</Get>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events />
|
||||
<Indexers />
|
||||
<Constructors />
|
||||
|
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This file is
|
||||
|
||||
Copyright 2007,2008,2009,2010 Rustici Software, LLC
|
||||
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
|
||||
-->
|
||||
<Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
|
||||
<Imports>
|
||||
<Import>java.util.List</Import>
|
||||
<Import>CS2JNet.System.Text.RegularExpressions.Match</Import>
|
||||
</Imports>
|
||||
<Java>List*[Match]*</Java>
|
||||
<Name>System.Text.RegularExpressions.MatchCollection</Name>
|
||||
<Uses />
|
||||
<Inherits>
|
||||
<Type>System.Collections.Generic.IList*[System.Text.RegularExpressions.Match]*</Type>
|
||||
</Inherits>
|
||||
<Methods />
|
||||
<Properties />
|
||||
<Events />
|
||||
<Indexers>
|
||||
</Indexers>
|
||||
<Constructors>
|
||||
</Constructors>
|
||||
<Fields />
|
||||
<Casts />
|
||||
<UnaryOps />
|
||||
<BinaryOps />
|
||||
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /><DigestValue>/NAwgdUvZuJRzEnlky9ue6sLWIc=</DigestValue></Reference></SignedInfo><SignatureValue>AVizzM2k9+WSxJekoW45/t/cpEHgGLy2wYWAC9lirjVkTSEkvg+uhCM32tV+6WS4kLUWUPkvAADftndYCs/OI07BLrBG5y/OBFJSs22Aks1P8h972Q33FMPKZfrf7pVR+hhYSQuJPyLxIy0pLBXWOicqlk0jmuojI1oYYGH9+rE=</SignatureValue></Signature></Class>
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This file is
|
||||
@ -9,7 +9,7 @@
|
||||
-->
|
||||
<Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
|
||||
<Imports>
|
||||
<Import>java.util.regex.*</Import>
|
||||
<Import>java.util.regex.Pattern</Import>
|
||||
</Imports>
|
||||
<Java>Pattern</Java>
|
||||
<Name>System.Text.RegularExpressions.Regex</Name>
|
||||
@ -17,8 +17,10 @@
|
||||
<Inherits> <Type>System.Object</Type> </Inherits>
|
||||
<Methods>
|
||||
<Method>
|
||||
<Imports />
|
||||
<Java>${this:16}.matcher(${input})</Java>
|
||||
<Imports>
|
||||
<Import>CS2JNet.System.Text.RegularExpressions.Match</Import>
|
||||
</Imports>
|
||||
<Java>Match.mk(${this}, ${input})</Java>
|
||||
<Params>
|
||||
<Param>
|
||||
<Type>System.String</Type>
|
||||
@ -28,6 +30,38 @@
|
||||
<Name>Match</Name>
|
||||
<Return>System.Text.RegularExpressions.Match</Return>
|
||||
</Method>
|
||||
<Method>
|
||||
<Imports>
|
||||
<Import>CS2JNet.System.Text.RegularExpressions.Match</Import>
|
||||
</Imports>
|
||||
<Java>Match.mk(${this}, ${input}, ${startat})</Java>
|
||||
<Params>
|
||||
<Param>
|
||||
<Type>System.String</Type>
|
||||
<Name>input</Name>
|
||||
</Param>
|
||||
<Param>
|
||||
<Type>System.Int32</Type>
|
||||
<Name>startat</Name>
|
||||
</Param>
|
||||
</Params>
|
||||
<Name>Match</Name>
|
||||
<Return>System.Text.RegularExpressions.Match</Return>
|
||||
</Method>
|
||||
<Method>
|
||||
<Imports>
|
||||
<Import>CS2JNet.System.Text.RegularExpressions.Match</Import>
|
||||
</Imports>
|
||||
<Java>Match.mkMatches(${this}, ${input})</Java>
|
||||
<Params>
|
||||
<Param>
|
||||
<Type>System.String</Type>
|
||||
<Name>input</Name>
|
||||
</Param>
|
||||
</Params>
|
||||
<Name>Matches</Name>
|
||||
<Return>System.Collections.Generic.Collection*[Match]*</Return>
|
||||
</Method>
|
||||
<Method>
|
||||
<Imports />
|
||||
<Java>${this:16}.matcher(${input}).matches()</Java>
|
||||
@ -42,7 +76,7 @@
|
||||
</Method>
|
||||
<Method>
|
||||
<Imports>
|
||||
<Import>java.util.regex.*</Import>
|
||||
<Import>java.util.regex.Pattern</Import>
|
||||
</Imports>
|
||||
<Java>Pattern.compile(${pattern}).matcher(${input}).matches()</Java>
|
||||
<Params>
|
||||
@ -60,7 +94,7 @@
|
||||
</Method>
|
||||
<Method>
|
||||
<Imports>
|
||||
<Import>java.util.regex.*</Import>
|
||||
<Import>java.util.regex.Pattern</Import>
|
||||
</Imports>
|
||||
<Java>Pattern.compile(${pattern}).matcher(${input}).replaceAll(${replacement})</Java>
|
||||
<Params>
|
||||
@ -87,14 +121,14 @@
|
||||
<Constructors>
|
||||
<Constructor>
|
||||
<Imports>
|
||||
<Import>java.util.regex.*</Import>
|
||||
<Import>java.util.regex.Pattern</Import>
|
||||
</Imports>
|
||||
<Java>new Pattern()</Java>
|
||||
<Params />
|
||||
</Constructor>
|
||||
<Constructor>
|
||||
<Imports>
|
||||
<Import>java.util.regex.*</Import>
|
||||
<Import>java.util.regex.Pattern</Import>
|
||||
</Imports>
|
||||
<Java>Pattern.compile(${pattern})</Java>
|
||||
<Params>
|
||||
@ -104,6 +138,22 @@
|
||||
</Param>
|
||||
</Params>
|
||||
</Constructor>
|
||||
<Constructor>
|
||||
<Imports>
|
||||
<Import>java.util.regex.Pattern</Import>
|
||||
</Imports>
|
||||
<Java>Pattern.compile(${pattern}, ${options})</Java>
|
||||
<Params>
|
||||
<Param>
|
||||
<Type>System.String</Type>
|
||||
<Name>pattern</Name>
|
||||
</Param>
|
||||
<Param>
|
||||
<Type>System.Text.RegularExpressions.RegexOptions</Type>
|
||||
<Name>options</Name>
|
||||
</Param>
|
||||
</Params>
|
||||
</Constructor>
|
||||
</Constructors>
|
||||
<Fields />
|
||||
<Casts />
|
||||
|
@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This file is
|
||||
|
||||
Copyright 2007,2008,2009,2010 Rustici Software, LLC
|
||||
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
|
||||
-->
|
||||
<Enum xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
|
||||
<Imports>
|
||||
<Import>CS2JNet.System.Text.RegularExpressions.RegexOptions</Import>
|
||||
</Imports>
|
||||
<Java>int</Java>
|
||||
<Name>System.Text.RegularExpressions.RegexOptions</Name>
|
||||
<Inherits>
|
||||
<Type>System.Enum</Type>
|
||||
</Inherits>
|
||||
<Members>
|
||||
<Member>
|
||||
<Java>0 /* RegexOptions.None */</Java>
|
||||
<Name>None</Name>
|
||||
</Member>
|
||||
<Member>
|
||||
<Imports><Import>java.util.regex.Pattern</Import></Imports>
|
||||
<Java>Pattern.CASE_INSENSITIVE </Java>
|
||||
<Name>IgnoreCase</Name>
|
||||
</Member>
|
||||
<Member>
|
||||
<Imports><Import>java.util.regex.Pattern</Import></Imports>
|
||||
<Java>Pattern.MULTILINE</Java>
|
||||
<Name>Multiline</Name>
|
||||
</Member>
|
||||
<Member>
|
||||
<Java>${this:16}.ExplicitCapture</Java>
|
||||
<Name>ExplicitCapture</Name>
|
||||
</Member>
|
||||
<Member>
|
||||
<Java>0 /* RegexOptions.Compiled */</Java>
|
||||
<Name>Compiled</Name>
|
||||
</Member>
|
||||
<Member>
|
||||
<Java>${this:16}.Singleline</Java>
|
||||
<Name>Singleline</Name>
|
||||
</Member>
|
||||
<Member>
|
||||
<Java>${this:16}.IgnorePatternWhitespace</Java>
|
||||
<Name>IgnorePatternWhitespace</Name>
|
||||
</Member>
|
||||
<Member>
|
||||
<Java>${this:16}.RightToLeft</Java>
|
||||
<Name>RightToLeft</Name>
|
||||
</Member>
|
||||
<Member>
|
||||
<Java>${this:16}.ECMAScript</Java>
|
||||
<Name>ECMAScript</Name>
|
||||
</Member>
|
||||
<Member>
|
||||
<Java>${this:16}.CultureInvariant</Java>
|
||||
<Name>CultureInvariant</Name>
|
||||
</Member>
|
||||
</Members>
|
||||
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /><DigestValue>mo6ChmPjcAlAo0NBWLLZbsocykw=</DigestValue></Reference></SignedInfo><SignatureValue>RlUioSuamZxr9dmH+n+zDAoS31RAR3VRqGwbq0J8Ew28sRdZoXTjz2yJwWvSZIzMRNeMc0v8VZbLRMEM39bSKH51gWKuQ8TFyzTBwMzQDeDsNO5kzdxcE1DYGnZKKplPDKPM8n9mlpuDYginKU8dk3dA/CtPgAmc7X90AuPIhew=</SignatureValue></Signature></Enum>
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author(s):
|
||||
|
||||
Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
*/
|
||||
|
||||
package CS2JNet.System.Text.RegularExpressions;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
/**
|
||||
* @author keving
|
||||
*
|
||||
*/
|
||||
public class Group {
|
||||
|
||||
private Match match = null;
|
||||
private int index = -1;
|
||||
/**
|
||||
* @return the matcher
|
||||
*/
|
||||
public Match getMatch() {
|
||||
return match;
|
||||
}
|
||||
/**
|
||||
* @param matcher the matcher to set
|
||||
*/
|
||||
public void setMatch(Match match) {
|
||||
this.match = match;
|
||||
}
|
||||
/**
|
||||
* @return the index
|
||||
*/
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
/**
|
||||
* @param index the index to set
|
||||
*/
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the string matched by group
|
||||
* If index is default then the whole match, else the group(index)
|
||||
*/
|
||||
public String getValue() {
|
||||
return (index >= 0 ? match.getMatcher().group(index) : match.getMatcher().group());
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author(s):
|
||||
|
||||
Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
*/
|
||||
|
||||
package CS2JNet.System.Text.RegularExpressions;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import CS2JNet.System.NotImplementedException;
|
||||
|
||||
/**
|
||||
* @author keving
|
||||
*
|
||||
*/
|
||||
public class GroupCollection {
|
||||
|
||||
private Match match = null;
|
||||
|
||||
public static GroupCollection mk(Match m) {
|
||||
GroupCollection ret = new GroupCollection();
|
||||
ret.match = m;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
public Group get(int i) {
|
||||
Group ret = new Group();
|
||||
ret.setMatch(this.match);
|
||||
ret.setIndex(i);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
* @throws NotImplementedException
|
||||
*/
|
||||
public Group get(String name) throws NotImplementedException {
|
||||
throw new NotImplementedException("CS2J: No implementation for named groups in regular expressions");
|
||||
}
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
/*
|
||||
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author(s):
|
||||
|
||||
Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
*/
|
||||
|
||||
package CS2JNet.System.Text.RegularExpressions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author keving
|
||||
*
|
||||
*/
|
||||
public class Match {
|
||||
|
||||
private Matcher matcher = null;
|
||||
private boolean lastMatchSuccess = false;
|
||||
private int lastMatchStartIdx = 0;
|
||||
private int lastMatchLength = 0;
|
||||
|
||||
private String input = "";
|
||||
private Pattern pat = null;
|
||||
|
||||
/**
|
||||
* @return the matcher
|
||||
*/
|
||||
public Matcher getMatcher() {
|
||||
return matcher;
|
||||
}
|
||||
/**
|
||||
* @param matcher the matcher to set
|
||||
*/
|
||||
public void setMatcher(Matcher matcher) {
|
||||
this.matcher = matcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the string matched by the last match
|
||||
*/
|
||||
public String getValue() {
|
||||
return matcher.group();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the string matched by the last match
|
||||
*/
|
||||
public boolean getSuccess() {
|
||||
return lastMatchSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the length of string matched by the last match
|
||||
*/
|
||||
public int length() {
|
||||
return lastMatchLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the start index of string matched by the last match
|
||||
*/
|
||||
public int start() {
|
||||
return lastMatchStartIdx;
|
||||
}
|
||||
|
||||
public Match nextMatch() {
|
||||
return mk(this.pat, this.input,
|
||||
this.lastMatchLength == 0 ? this.lastMatchStartIdx + 1 : this.lastMatchStartIdx + this.lastMatchLength);
|
||||
}
|
||||
|
||||
public static Match mk(Pattern pat, String input, int startat) {
|
||||
Match ret = new Match();
|
||||
ret.pat = pat;
|
||||
ret.input = input;
|
||||
ret.matcher = pat.matcher(input);
|
||||
ret.lastMatchSuccess = ret.matcher.find(startat);
|
||||
if (ret.lastMatchSuccess) {
|
||||
ret.lastMatchStartIdx = ret.matcher.start();
|
||||
ret.lastMatchLength = ret.matcher.end() -ret.matcher.start();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Match mk(Pattern pat, String input) {
|
||||
return mk(pat, input, 0);
|
||||
}
|
||||
|
||||
public static List<Match> mkMatches(Pattern pat, String input) {
|
||||
List<Match> ret = new ArrayList<Match>();
|
||||
Match m = mk(pat, input);
|
||||
while (m.getSuccess()) {
|
||||
ret.add(m);
|
||||
m = m.nextMatch();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -16,6 +16,7 @@ namespace Tester
|
||||
|
||||
// Tester.Misc.RenameTest.RNMain("hello world");
|
||||
Tester.Misc.Sorter.Example.SorterMain();
|
||||
Tester.Misc.RegexTest.RegexMain();
|
||||
|
||||
}
|
||||
}
|
||||
|
42
CSharpTranslator/tests/Tester/Misc/Regex/RegexTest.cs
Normal file
42
CSharpTranslator/tests/Tester/Misc/Regex/RegexTest.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Tester.Misc
|
||||
{
|
||||
public class RegexTest
|
||||
{
|
||||
public RegexTest ()
|
||||
{
|
||||
}
|
||||
|
||||
public static void RegexMain() {
|
||||
|
||||
Regex r = new Regex(@"(\d+)\s+(\d+)");
|
||||
Match m = r.Match(" 001 002 003 004 ");
|
||||
while (m.Success)
|
||||
{
|
||||
Console.WriteLine("Match: '{0}'", m.Value);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (m.Groups[i] != null && m.Groups[i].Value.Length > 0)
|
||||
{
|
||||
Console.WriteLine("Group {0}: '{1}'", i, m.Groups[i].Value);
|
||||
}
|
||||
}
|
||||
|
||||
m = m.NextMatch();
|
||||
}
|
||||
MatchCollection matches = r.Matches(" 001 002 003 004 ");
|
||||
foreach (Match mi in matches)
|
||||
{
|
||||
Console.WriteLine("Match: '{0}'", mi.Value);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (mi.Groups[i] != null && mi.Groups[i].Value.Length > 0)
|
||||
{
|
||||
Console.WriteLine("Group {0}: '{1}'", i, mi.Groups[i].Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,9 +59,11 @@
|
||||
<Compile Include="Misc\RenameTest.cs" />
|
||||
<Compile Include="Misc\newmodifier.cs" />
|
||||
<Compile Include="Misc\Sorter.cs" />
|
||||
<Compile Include="Misc\Regex\RegexTest.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<Folder Include="Enums\" />
|
||||
<Folder Include="Misc\Regex\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user