[Git][java-team/re2j][master] 13 commits: Converted debian/watch to the version 5 format
Emmanuel Bourg (@ebourg)
gitlab at salsa.debian.org
Fri Nov 13 18:25:16 GMT 2026
Emmanuel Bourg pushed to branch master at Debian Java Maintainers / re2j
Commits:
ec83ce58 by Emmanuel Bourg at 2026-11-13T12:04:21+01:00
Converted debian/watch to the version 5 format
- - - - -
620457bb by Emmanuel Bourg at 2026-11-13T12:04:30+01:00
New upstream version 1.8+dfsg
- - - - -
4e008cb3 by Emmanuel Bourg at 2026-11-13T12:04:30+01:00
Update upstream source from tag 'upstream/1.8+dfsg'
Update to upstream version '1.8+dfsg'
with Debian dir 6af6b34de03c7ee6042ad580f551efe8d27bfaa6
- - - - -
df5f8f45 by Emmanuel Bourg at 2026-11-13T19:13:13+01:00
Build with gradle-debian-helper 3.0
- - - - -
483c7c32 by Emmanuel Bourg at 2026-11-13T19:13:13+01:00
Standards-Version updated to 4.7.4
- - - - -
9a434590 by Emmanuel Bourg at 2026-11-13T19:13:13+01:00
Removed the Priority field
- - - - -
0741d971 by Emmanuel Bourg at 2026-11-13T19:13:13+01:00
Removed the Rules-Requires-Root field
- - - - -
27fd18b1 by Emmanuel Bourg at 2026-11-13T19:13:23+01:00
Removed the redundant build dependency on debhelper
- - - - -
2466c7be by Emmanuel Bourg at 2026-11-13T19:13:23+01:00
Removed the unused substitution variables from Depends
- - - - -
502cbd0b by Emmanuel Bourg at 2026-11-13T19:13:23+01:00
No longer install the Unicode table generator (unicode.jar)
- - - - -
94df64bf by Emmanuel Bourg at 2026-11-13T19:13:23+01:00
Moved the source package to the java section
- - - - -
c17adb6c by Emmanuel Bourg at 2026-11-13T19:13:23+01:00
Wrap and sort
- - - - -
daa0f70f by Emmanuel Bourg at 2026-11-13T19:15:16+01:00
Upload to unstable
- - - - -
25 changed files:
- RELEASING.md
- build.gradle
- debian/changelog
- debian/control
- + debian/gradle.ignoreRules
- debian/libre2j-java.poms
- − debian/patches/gradle.patch
- − debian/patches/no_googlejavaformat.patch
- − debian/patches/series
- debian/watch
- java/com/google/re2j/Inst.java
- java/com/google/re2j/Matcher.java
- java/com/google/re2j/Parser.java
- java/com/google/re2j/Pattern.java
- java/com/google/re2j/RE2.java
- java/com/google/re2j/Regexp.java
- java/com/google/re2j/Unicode.java
- javatests/com/google/re2j/ApiTestUtils.java
- javatests/com/google/re2j/CharClassTest.java
- javatests/com/google/re2j/MatcherTest.java
- javatests/com/google/re2j/ParserTest.java
- javatests/com/google/re2j/PatternTest.java
- javatests/com/google/re2j/RE2CompileTest.java
- javatests/com/google/re2j/RE2Test.java
- javatests/com/google/re2j/UnicodeTest.java
Changes:
=====================================
RELEASING.md
=====================================
@@ -42,24 +42,37 @@ $ gpg --keyserver keys.openpgp.org --send-keys 90ABCDEF
gpg: sending key 1234567890ABCDEF to hkp://keys.openpgp.org
```
+## Gradle properties
+
+Add the following properties to `$HOME/gradle.properties`:
+
+```
+signing.gnupg.executable=gpg
+signing.gnupg.useLegacyGpg=true
+signing.gnupg.keyName=ABCDEF01
+
+# Not to be confused with your Sonatype login username and password
+ossrhUsername=yourSonatypeToken
+ossrhPassword=yourSonatypeTokenPassword
+```
+
# Making the release
In a shell, change into the RE2/J source code root directory (the one
containing `build.gradle`). Then:
* edit `build.gradle` and set `version` to the name of the next release
- (e.g. "1.8").
+ (e.g. "1.9").
* change the download instructions in `README.md` to reflect the new version
number
* `git commit` the version name change
-* `git tag re2j-<versionName>`, e.g. `git tag re2j-1.8`
+* `git tag re2j-<versionName>`, e.g. `git tag re2j-1.9`
* `git push --tags`
Now you're ready to build and push the release.
```
-./gradlew -Psonatype.username='sonatypeUsername' -Psonatype.password='sonatypeApiKey' \
- clean bintrayUpload
+./gradlew clean uploadArchives
```
Once successful, the new version needs to be published:
=====================================
build.gradle
=====================================
@@ -2,7 +2,7 @@
plugins {
id 'java-library'
id 'wrapper'
- id 'maven-publish'
+ id 'maven'
id 'io.github.gradle-nexus.publish-plugin' version '1.1.0'
id 'com.github.sherter.google-java-format' version '0.3.2'
id 'net.ltgt.errorprone' version '2.0.2'
@@ -24,7 +24,8 @@ cobertura.coverageFormats = ['html', 'xml']
// The name of the release we're working on. See RELEASING.md for details.
group = "com.google.re2j"
-version = "1.7"
+archivesBaseName = "re2j"
+version = "1.8"
wrapper {
gradleVersion '5.2'
@@ -93,56 +94,60 @@ dependencies {
testRuntime "org.slf4j:slf4j-api:1.7.10"
}
-task sourceJar(type: Jar) {
- baseName 'sources'
-
- from sourceSets.main.allJava
- from sourceSets.gwt.allSource
+task javadocJar(type: Jar) {
+ classifier = 'javadoc'
+ from javadoc
}
-task javadocJar(type: Jar, dependsOn: javadoc) {
- baseName 'javadoc'
-
- from javadoc.destinationDir
+task sourcesJar(type: Jar) {
+ classifier = 'sources'
+ from sourceSets.main.allSource
}
-def appendMavenCentralMetadata(Node node) {
- node.appendNode('name', 'RE2/J')
- node.appendNode('description', 'Linear time regular expressions for Java')
- node.appendNode('url', 'http://github.com/google/re2j')
-
- def license = node.appendNode('licenses').appendNode('license')
- license.appendNode('name', 'Go License')
- license.appendNode('url', 'https://golang.org/LICENSE')
- license.appendNode('distribution', 'repo')
-
- node.appendNode('scm').appendNode('url', 'https://github.com/google/re2j.git')
-
- def developerInfo = node.appendNode('developers').appendNode('developer')
- developerInfo.appendNode('id', 'dev')
- developerInfo.appendNode('name', 'The RE2/J Contributors')
- developerInfo.appendNode('email', 're2j-discuss at googlegroups.com')
+artifacts {
+ archives javadocJar, sourcesJar
}
-publishing {
- publications {
- mavenJava(MavenPublication) {
- from components.java
+uploadArchives {
+ repositories {
+ mavenDeployer {
+ beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
- artifact sourceJar {
- classifier 'sources'
+ repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
+ authentication(userName: findProperty('ossrhUsername') ?: '',
+ password: findProperty('ossrhPassword') ?: '')
}
- artifact javadocJar {
- classifier 'javadoc'
+ snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
+ authentication(userName: findProperty('ossrhUsername') ?: '',
+ password: findProperty('ossrhPassword') ?: '')
}
- groupId 'com.google.re2j'
- artifactId 're2j'
- version project.version
-
- pom.withXml {
- appendMavenCentralMetadata(asNode())
+ pom.project {
+ name 'RE2/J'
+ packaging 'jar'
+ description 'Linear time regular expressions for Java'
+ url 'http://github.com/google/re2j'
+
+ scm {
+ url 'https://github.com/google/re2j.git'
+ }
+
+ licenses {
+ license {
+ name 'Go License'
+ url 'https://golang.org/LICENSE'
+ distribution 'repo'
+ }
+ }
+
+ developers {
+ developer {
+ id 'dev'
+ name 'The RE2/J Contributors'
+ email 're2j-discuss at googlegroups.com'
+ }
+ }
}
}
}
@@ -151,16 +156,7 @@ publishing {
signing {
useGpgCmd()
- sign publishing.publications.mavenJava
-}
-
-nexusPublishing {
- repositories {
- sonatype {
- username = findProperty('sonatype.username')
- password = findProperty('sonatype.password')
- }
- }
+ sign configurations.archives
}
// If Java formatter checks fail, tell the user how to fix them.
=====================================
debian/changelog
=====================================
@@ -1,3 +1,17 @@
+re2j (1.8+dfsg-1) unstable; urgency=medium
+
+ * Team upload.
+ * New upstream release
+ * Converted debian/watch to the version 5 format
+ * Build with gradle-debian-helper 3.0
+ * Standards-Version updated to 4.7.4
+ * Removed the Priority field
+ * Removed the Rules-Requires-Root field
+ * Removed the redundant build dependency on debhelper
+ * No longer install the Unicode table generator (unicode.jar)
+
+ -- Emmanuel Bourg <ebourg at apache.org> Fri, 13 Nov 2026 19:15:02 +0100
+
re2j (1.7+dfsg-1) unstable; urgency=medium
* New upstream release
=====================================
debian/control
=====================================
@@ -1,27 +1,20 @@
Source: re2j
+Section: java
Maintainer: Debian Java Maintainers <pkg-java-maintainers at lists.alioth.debian.org>
Uploaders: Vincent Prat <vivi at debian.org>
-Section: libs
-Priority: optional
-Build-Depends: debhelper (>= 13),
- debhelper-compat (= 13),
- gradle-debian-helper,
- libicu4j-java,
- libjavapoet-java,
- maven-repo-helper
-Standards-Version: 4.6.1
+Build-Depends:
+ debhelper-compat (= 13),
+ gradle-debian-helper (>= 3.0),
+ maven-repo-helper
+Standards-Version: 4.7.4
Vcs-Browser: https://salsa.debian.org/java-team/re2j
Vcs-Git: https://salsa.debian.org/java-team/re2j.git
Homepage: https://github.com/google/re2j
-Rules-Requires-Root: no
Package: libre2j-java
Architecture: all
Multi-Arch: foreign
-Section: java
-Depends: ${shlibs:Depends},
- ${misc:Depends},
- ${java:Depends}
+Depends: ${misc:Depends}
Description: RE2/J: linear time regular expression matching in Java
RE2 is a regular expression engine that runs in time linear in the size of the
input. RE2/J is a port of RE2 to pure Java.
=====================================
debian/gradle.ignoreRules
=====================================
@@ -0,0 +1,10 @@
+# Ignored plugins and blocks
+com.github.hierynomus.license license,com.hierynomus.gradle.license.tasks.LicenseCheck
+com.github.sherter.google-java-format verifyGoogleJavaFormat
+io.github.gradle-nexus.publish-plugin
+license license
+net.ltgt.errorprone errorprone,errorproneJavac
+net.saliman.cobertura cobertura
+
+# Ignored projects
+:unicode
=====================================
debian/libre2j-java.poms
=====================================
@@ -1,2 +1 @@
build/debian/re2j.pom --artifact=build/libs/*.jar --java-lib
-unicode/build/debian/unicode.pom --artifact=unicode/build/libs/*.jar --java-lib
=====================================
debian/patches/gradle.patch deleted
=====================================
@@ -1,187 +0,0 @@
-Author: Vincent Prat <vivi at debian.org>
-Description: Fix Gradle configuration files to make them compatible with Debian
-Forwarded: not-needed
---- a/build.gradle
-+++ b/build.gradle
-@@ -3,24 +3,24 @@
- id 'java-library'
- id 'wrapper'
- id 'maven-publish'
-- id 'io.github.gradle-nexus.publish-plugin' version '1.1.0'
-- id 'com.github.sherter.google-java-format' version '0.3.2'
-- id 'net.ltgt.errorprone' version '2.0.2'
-+// id 'io.github.gradle-nexus.publish-plugin' version '1.1.0'
-+// id 'com.github.sherter.google-java-format' version '0.3.2'
-+// id 'net.ltgt.errorprone' version '2.0.2'
- id 'idea'
- id 'signing'
-
- // code coverage support
-- id 'net.saliman.cobertura' version '2.5.4'
-+// id 'net.saliman.cobertura' version '2.5.4'
-
- // Add license plugin. By default, this plugin only applies to the root
- // project. Since we need license enforcement for benchmarks and the
- // Unicode table generator, "apply false" specifies that the plugin should
- // be downloaded and made available to Gradle, but not applied yet. See the
- // allprojects section below for where this plugin is actually applied.
-- id 'com.github.hierynomus.license' version '0.15.0' apply false
-+// id 'com.github.hierynomus.license' version '0.15.0' apply false
- }
-
--cobertura.coverageFormats = ['html', 'xml']
-+//cobertura.coverageFormats = ['html', 'xml']
-
- // The name of the release we're working on. See RELEASING.md for details.
- group = "com.google.re2j"
-@@ -34,7 +34,9 @@
- targetCompatibility = 1.6
-
- repositories {
-- mavenCentral()
-+ maven {
-+ url "file:///usr/share/mave-repo"
-+ }
- }
-
- sourceSets {
-@@ -81,8 +83,8 @@
- }
-
- dependencies {
-- errorproneJavac 'com.google.errorprone:javac:9+181-r4173-1'
-- errorprone 'com.google.errorprone:error_prone_core:2.10.0'
-+ //errorproneJavac 'com.google.errorprone:javac:9+181-r4173-1'
-+ //errorprone 'com.google.errorprone:error_prone_core:2.10.0'
-
- testCompile 'junit:junit:4.12'
- testCompile 'com.google.gwt:gwt-dev:2.9.0'
-@@ -149,19 +151,19 @@
- }
-
- signing {
-- useGpgCmd()
-+ //useGpgCmd()
-
-- sign publishing.publications.mavenJava
-+ //sign publishing.publications.mavenJava
- }
-
--nexusPublishing {
-- repositories {
-- sonatype {
-- username = findProperty('sonatype.username')
-- password = findProperty('sonatype.password')
-- }
-- }
--}
-+//nexusPublishing {
-+// repositories {
-+// sonatype {
-+// username = findProperty('sonatype.username')
-+// password = findProperty('sonatype.password')
-+// }
-+// }
-+//}
-
- // If Java formatter checks fail, tell the user how to fix them.
- task printFormatHelperMessage {
-@@ -170,47 +172,50 @@
- 'Use ./gradlew googleJavaFormat to reformat the broken files')
- }
- }
--verifyGoogleJavaFormat.finalizedBy printFormatHelperMessage
--printFormatHelperMessage.onlyIf { verifyGoogleJavaFormat.state.failure != null }
-+//verifyGoogleJavaFormat.finalizedBy printFormatHelperMessage
-+//printFormatHelperMessage.onlyIf { verifyGoogleJavaFormat.state.failure != null }
-
--import com.hierynomus.gradle.license.tasks.LicenseCheck
-+//import com.hierynomus.gradle.license.tasks.LicenseCheck
-
- // By default, this plugin only applies to the root project. We apply it here
- // manually to all projects so that even the subprojects receive license
- // enforcement.
-+//allprojects {
-+// apply plugin: "license"
-+//
-+// license {
-+// header rootProject.file('LICENSE.header')
-+// ext.year = Calendar.getInstance().get(Calendar.YEAR)
-+// strictCheck true
-+// skipExistingHeaders true
-+//
-+// mapping {
-+// // Without this, the plugin adds javadoc-style comments to the top
-+// // of each Java source file.
-+// java = 'SLASHSTAR_STYLE'
-+// }
-+//
-+// include '**/*.gradle'
-+// include '**/*.java'
-+// include '**/*.xml'
-+// include '**/*.pl'
-+// }
-+//
-+// // Each license check task gets a new "help message" task to tell the
-+// // user how to fix license violations.
-+// tasks.withType(LicenseCheck) { checkTask ->
-+// def helpMessageTask = task "${checkTask.name}HelpMessage" {
-+// doLast {
-+// throw new GradleException(
-+// 'Some files lack an appropriate license header.\n' +
-+// 'Run ./gradlew licenseFormat to add one.')
-+// }
-+// }
-+//
-+// checkTask.finalizedBy helpMessageTask
-+// helpMessageTask.onlyIf { checkTask.state.failure != null }
-+// }
- allprojects {
-- apply plugin: "license"
--
-- license {
-- header rootProject.file('LICENSE.header')
-- ext.year = Calendar.getInstance().get(Calendar.YEAR)
-- strictCheck true
-- skipExistingHeaders true
--
-- mapping {
-- // Without this, the plugin adds javadoc-style comments to the top
-- // of each Java source file.
-- java = 'SLASHSTAR_STYLE'
-- }
--
-- include '**/*.gradle'
-- include '**/*.java'
-- include '**/*.xml'
-- include '**/*.pl'
-- }
--
-- // Each license check task gets a new "help message" task to tell the
-- // user how to fix license violations.
-- tasks.withType(LicenseCheck) { checkTask ->
-- def helpMessageTask = task "${checkTask.name}HelpMessage" {
-- doLast {
-- throw new GradleException(
-- 'Some files lack an appropriate license header.\n' +
-- 'Run ./gradlew licenseFormat to add one.')
-- }
-- }
--
-- checkTask.finalizedBy helpMessageTask
-- helpMessageTask.onlyIf { checkTask.state.failure != null }
-- }
-+ group = 'com.google.re2j'
-+ version = "1.7"
- }
---- a/unicode/build.gradle
-+++ b/unicode/build.gradle
-@@ -10,7 +10,7 @@
- }
-
- dependencies {
-- compile 'com.google.googlejavaformat:google-java-format:1.0'
-+// compile 'com.google.googlejavaformat:google-java-format:1.0'
- compile 'com.squareup:javapoet:1.12.1'
- compile 'com.ibm.icu:icu4j:4.8.2'
- compile 'com.google.guava:guava:29.0-jre'
=====================================
debian/patches/no_googlejavaformat.patch deleted
=====================================
@@ -1,35 +0,0 @@
-Author: Vincent Prat <vivi at debian.org>
-Description: Disables formatting of code by google-java-format
-Forwarded: not-needed
---- a/unicode/src/main/java/com/google/re2j/UnicodeTablesGenerator.java
-+++ b/unicode/src/main/java/com/google/re2j/UnicodeTablesGenerator.java
-@@ -9,8 +9,8 @@
- import com.google.common.collect.Sets;
- import com.google.common.collect.SortedSetMultimap;
- import com.google.common.collect.TreeMultimap;
--import com.google.googlejavaformat.java.Formatter;
--import com.google.googlejavaformat.java.FormatterException;
-+//import com.google.googlejavaformat.java.Formatter;
-+//import com.google.googlejavaformat.java.FormatterException;
- import com.ibm.icu.impl.UPropertyAliases;
- import com.ibm.icu.lang.UCharacter;
- import com.ibm.icu.lang.UCharacterCategory;
-@@ -279,12 +279,12 @@
- .build();
-
- String source = javaFile.toString();
-- try {
-- source = new Formatter().formatSource(source);
-- } catch (FormatterException e) {
-- System.err.println("google-java-format reported an error, the output is most likely invalid");
-- e.printStackTrace();
-- }
-+// try {
-+// source = new Formatter().formatSource(source);
-+// } catch (FormatterException e) {
-+// System.err.println("google-java-format reported an error, the output is most likely invalid");
-+// e.printStackTrace();
-+// }
-
- System.out.print(source);
- }
=====================================
debian/patches/series deleted
=====================================
@@ -1,2 +0,0 @@
-gradle.patch
-no_googlejavaformat.patch
=====================================
debian/watch
=====================================
@@ -1,3 +1,7 @@
-version=4
-opts=repacksuffix=+dfsg,dversionmangle=s/\+dfsg//g \
- https://github.com/google/re2j/tags .*/re2j-(\d[.\d]*)\.tar\.gz
+Version: 5
+Template: GitHub
+Owner: google
+Project: re2j
+Dversion-Mangle: s/\+dfsg\d*$//
+Repacksuffix: +dfsg
+Compression: xz
=====================================
java/com/google/re2j/Inst.java
=====================================
@@ -50,17 +50,15 @@ final class Inst {
// class.
if (runes.length == 1) {
int r0 = runes[0];
- if (r == r0) {
- return true;
- }
+
+ // If this pattern is case-insensitive, apply Unicode case folding to compare the two runes.
+ // Note that this may result in a case-folding loop when executed on a JVM newer than the version used
+ // to generate Unicode data for re2j, so attempt to reduce the chance of that occurring
+ // by performing case folding on |r0| from the pattern rather than |r| from the input.
if ((arg & RE2.FOLD_CASE) != 0) {
- for (int r1 = Unicode.simpleFold(r0); r1 != r0; r1 = Unicode.simpleFold(r1)) {
- if (r == r1) {
- return true;
- }
- }
+ return Unicode.equalsIgnoreCase(r0, r);
}
- return false;
+ return r == r0;
}
// Peek at the first few pairs.
=====================================
java/com/google/re2j/Matcher.java
=====================================
@@ -7,6 +7,7 @@
package com.google.re2j;
import com.google.re2j.MatcherInput.Encoding;
+import java.io.UnsupportedEncodingException;
import java.util.Map;
/**
@@ -49,6 +50,9 @@ public final class Matcher {
// The number of submatches (groups) in the pattern.
private final int groupCount;
+ // The number of instructions in the pattern.
+ private final int numberOfInstructions;
+
private MatcherInput matcherInput;
// The input length in UTF16 codes.
@@ -76,6 +80,7 @@ public final class Matcher {
groupCount = re2.numberOfCapturingGroups();
groups = new int[2 + 2 * groupCount];
namedGroups = re2.namedGroups;
+ numberOfInstructions = re2.numberOfInstructions();
}
/** Creates a new {@code Matcher} with the given pattern and input. */
@@ -208,6 +213,20 @@ public final class Matcher {
return end(g);
}
+ /**
+ * Returns the program size of this pattern.
+ *
+ * <p>
+ * Similar to the C++ implementation, the program size is a very approximate measure of a regexp's
+ * "cost". Larger numbers are more expensive than smaller numbers.
+ * </p>
+ *
+ * @return the program size of this pattern
+ */
+ public int programSize() {
+ return numberOfInstructions;
+ }
+
/**
* Returns the most recent match.
*
@@ -363,7 +382,11 @@ public final class Matcher {
String substring(int start, int end) {
// UTF_8 is matched in binary mode. So slice the bytes.
if (matcherInput.getEncoding() == Encoding.UTF_8) {
- return new String(matcherInput.asBytes(), start, end - start);
+ try {
+ return new String(matcherInput.asBytes(), start, end - start, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e); // Not possible.
+ }
}
// This is fast for both StringBuilder and String.
=====================================
java/com/google/re2j/Parser.java
=====================================
@@ -28,7 +28,6 @@ class Parser {
private static final String ERR_INTERNAL_ERROR = "regexp/syntax: internal error";
// Parse errors
- private static final String ERR_INVALID_CHAR_CLASS = "invalid character class";
private static final String ERR_INVALID_CHAR_RANGE = "invalid character class range";
private static final String ERR_INVALID_ESCAPE = "invalid escape sequence";
private static final String ERR_INVALID_NAMED_CAPTURE = "invalid named capture";
@@ -1054,21 +1053,22 @@ class Parser {
// support all three as well. EcmaScript 4 uses only the Python form.
//
// In both the open source world (via Code Search) and the
- // Google source tree, (?P<expr>name) is the dominant form,
- // so that's the one we implement. One is enough.
+ // Google source tree, (?P<name>expr) and (?<name>expr) are the
+ // dominant forms of named captures and both are supported.
String s = t.rest();
- if (s.startsWith("(?P<")) {
+ if (s.startsWith("(?P<") || s.startsWith("(?<")) {
// Pull out name.
- int end = s.indexOf('>');
+ int begin = s.charAt(2) == 'P' ? 4 : 3;
+ int end = s.indexOf('>', begin);
if (end < 0) {
throw new PatternSyntaxException(ERR_INVALID_NAMED_CAPTURE, s);
}
- String name = s.substring(4, end); // "name"
+ String name = s.substring(begin, end); // "name"
t.skipString(name);
- t.skip(5); // "(?P<>"
+ t.skip(begin + 1); // "(?P<>" or "(?<>"
if (!isValidCaptureName(name)) {
throw new PatternSyntaxException(
- ERR_INVALID_NAMED_CAPTURE, s.substring(0, end)); // "(?P<name>"
+ ERR_INVALID_NAMED_CAPTURE, s.substring(0, end + 1)); // "(?P<name>" or "(?<name>"
}
// Like ordinary capture, but named.
Regexp re = op(Regexp.Op.LEFT_PAREN);
=====================================
java/com/google/re2j/Pattern.java
=====================================
@@ -300,6 +300,20 @@ public final class Pattern implements Serializable {
return pattern;
}
+ /**
+ * Returns the program size of this pattern.
+ *
+ * <p>
+ * Similar to the C++ implementation, the program size is a very approximate measure of a regexp's
+ * "cost". Larger numbers are more expensive than smaller numbers.
+ * </p>
+ *
+ * @return the program size of this pattern
+ */
+ public int programSize() {
+ return re2.numberOfInstructions();
+ }
+
/**
* Returns the number of capturing groups in this matcher's pattern. Group zero denotes the entire
* pattern and is excluded from this count.
=====================================
java/com/google/re2j/RE2.java
=====================================
@@ -209,6 +209,13 @@ class RE2 {
return numSubexp;
}
+ /**
+ * Returns the number of instructions in this compiled regular expression program.
+ */
+ int numberOfInstructions() {
+ return prog.numInst();
+ }
+
// get() returns a machine to use for matching |this|. It uses |this|'s
// machine cache if possible, to avoid unnecessary allocation.
Machine get() {
=====================================
java/com/google/re2j/Regexp.java
=====================================
@@ -10,6 +10,7 @@
package com.google.re2j;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Map;
/**
@@ -59,7 +60,7 @@ class Regexp {
int min, max; // min, max for REPEAT
int cap; // capturing index, for CAPTURE
String name; // capturing name, for CAPTURE
- Map<String, Integer> namedGroups; // map of group name -> capturing index
+ Map<String, Integer> namedGroups = Collections.emptyMap(); // map of group name -> capturing index
// Do update copy ctor when adding new fields!
Regexp(Op op) {
@@ -85,6 +86,7 @@ class Regexp {
runes = null;
cap = min = max = 0;
name = null;
+ this.namedGroups = Collections.emptyMap();
}
@Override
=====================================
java/com/google/re2j/Unicode.java
=====================================
@@ -122,5 +122,42 @@ class Unicode {
return Characters.toUpperCase(r);
}
+ // equalsIgnoreCase performs case-insensitive equality comparison
+ // on the given runes |r1| and |r2|, with special consideration
+ // for the likely scenario where both runes are ASCII characters.
+ // If non-ASCII, Unicode case folding will be performed on |r1|
+ // to compare it to |r2|.
+ // -1 is interpreted as the end-of-file mark.
+ static boolean equalsIgnoreCase(int r1, int r2) {
+ // Runes already match, or one of them is EOF
+ if (r1 < 0 || r2 < 0 || r1 == r2) {
+ return true;
+ }
+
+ // Fast path for the common case where both runes are ASCII characters.
+ // Coerces both runes to lowercase if applicable.
+ if (r1 <= MAX_ASCII && r2 <= MAX_ASCII) {
+ if ('A' <= r1 && r1 <= 'Z') {
+ r1 |= 0x20;
+ }
+
+ if ('A' <= r2 && r2 <= 'Z') {
+ r2 |= 0x20;
+ }
+
+ return r1 == r2;
+ }
+
+ // Fall back to full Unicode case folding otherwise.
+ // Invariant: r1 must be non-negative
+ for (int r = Unicode.simpleFold(r1); r != r1; r = Unicode.simpleFold(r)) {
+ if (r == r2) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
private Unicode() {} // uninstantiable
}
=====================================
javatests/com/google/re2j/ApiTestUtils.java
=====================================
@@ -159,6 +159,27 @@ public class ApiTestUtils {
assertEquals(count, mj.groupCount());
}
+ // Tests that both RE2 Patterns and Matchers give the same groupCount.
+ public static void testProgramSize(String pattern, int expectedSize) {
+ Pattern p = Pattern.compile(pattern);
+
+ String input = "foo";
+ byte[] inputBytes = getUtf8Bytes(input);
+ Matcher m1 = p.matcher(input);
+ Matcher m2 = p.matcher(inputBytes);
+
+ Truth.assertWithMessage("Pattern(\"%s\") program size", p)
+ .that(p.programSize())
+ .isEqualTo(expectedSize);
+ Truth.assertWithMessage("Matcher(\"%s\", \"%s\") program size", m1.pattern(), input)
+ .that(m1.programSize())
+ .isEqualTo(expectedSize);
+ Truth.assertWithMessage(
+ "Matcher(\"%s\", %s) program size", m2.pattern(), Arrays.toString(inputBytes))
+ .that(m2.programSize())
+ .isEqualTo(expectedSize);
+ }
+
public static void testGroup(String text, String regexp, String[] output) {
// RE2
Pattern p = Pattern.compile(regexp);
=====================================
javatests/com/google/re2j/CharClassTest.java
=====================================
@@ -7,13 +7,14 @@
package com.google.re2j;
import static com.google.re2j.Utils.stringToRunes;
-
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
-
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+ at RunWith(JUnit4.class)
public class CharClassTest {
private static CharClass cc(int... x) {
=====================================
javatests/com/google/re2j/MatcherTest.java
=====================================
@@ -94,8 +94,25 @@ public class MatcherTest {
ApiTestUtils.testReplaceFirst("aab", "a*?", "<$0>", "<>aab");
}
+ @Test
+ public void testProgramSize() {
+ // It is a simple delegation, but still test it.
+ // More test cases are covered in PatternTest#testProgramSize.
+ Pattern pattern = Pattern.compile("go+d");
+ int programSize = pattern.programSize();
+ Truth.assertWithMessage("Pattern program size").that(programSize).isGreaterThan(1);
+ Truth.assertWithMessage("Positive matcher program size")
+ .that(pattern.matcher("good").programSize())
+ .isEqualTo(programSize);
+ Truth.assertWithMessage("Negative matcher program size")
+ .that(pattern.matcher("bad").programSize())
+ .isEqualTo(programSize);
+ }
+
@Test
public void testGroupCount() {
+ // It is a simple delegation, but still test it.
+ // More test cases are covered in PatternTest#testGroupCount.
ApiTestUtils.testGroupCount("(a)(b(c))d?(e)", 4);
}
=====================================
javatests/com/google/re2j/ParserTest.java
=====================================
@@ -21,16 +21,18 @@ import static com.google.re2j.RE2.WAS_DOLLAR;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
+import com.google.common.truth.Truth;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.Map;
-
-import com.google.common.truth.Truth;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* @author adonovan at google.com (Alan Donovan)
*/
+ at RunWith(JUnit4.class)
public class ParserTest {
private interface RunePredicate {
@@ -232,6 +234,7 @@ public class ParserTest {
// Test named captures
{"(?P<name>a)", "cap{name:lit{a}}"},
+ {"(?<name>a)", "cap{name:lit{a}}"},
// Case-folded literals
{"[Aa]", "litfold{A}"},
@@ -404,6 +407,8 @@ public class ParserTest {
}
b.append('{');
switch (re.op) {
+ default:
+ break;
case END_TEXT:
if ((re.flags & WAS_DOLLAR) == 0) {
b.append("\\z");
@@ -530,12 +535,20 @@ public class ParserTest {
"(?P<name",
"(?P<x y>a)",
"(?P<>a)",
+ "(?<name>a",
+ "(?<name>",
+ "(?<name",
+ "(?<x y>a)",
+ "(?<>a)",
"[a-Z]",
"(?i)[a-Z]",
"a{100000}",
"a{100000,}",
// Group names may not be repeated
"(?P<foo>bar)(?P<foo>baz)",
+ "(?P<foo>bar)(?<foo>baz)",
+ "(?<foo>bar)(?P<foo>baz)",
+ "(?<foo>bar)(?<foo>baz)",
"\\x", // https://github.com/google/re2j/issues/103
"\\xv", // https://github.com/google/re2j/issues/103
};
@@ -550,6 +563,7 @@ public class ParserTest {
"\\Q\\\\\\\\\\E",
"(?:a)",
"(?P<name>a)",
+ "(?<name>a)",
};
private static final String[] ONLY_POSIX = {
@@ -573,7 +587,7 @@ public class ParserTest {
}
}
for (String regexp : ONLY_PERL) {
- Parser.parse(regexp, PERL);
+ Regexp unused = Parser.parse(regexp, PERL);
try {
Regexp re = Parser.parse(regexp, POSIX);
fail("parsing (POSIX) " + regexp + " should have failed, instead got " + dump(re));
@@ -588,7 +602,7 @@ public class ParserTest {
} catch (PatternSyntaxException e) {
/* ok */
}
- Parser.parse(regexp, POSIX);
+ Regexp unused = Parser.parse(regexp, POSIX);
}
}
=====================================
javatests/com/google/re2j/PatternTest.java
=====================================
@@ -164,9 +164,21 @@ public class PatternTest {
ApiTestUtils.testSplit(":", ":a::b", new String[] {"", "a", "", "b"});
}
+ @Test
+ public void testProgramSize() {
+ ApiTestUtils.testProgramSize("", 3);
+ ApiTestUtils.testProgramSize("a", 3);
+ ApiTestUtils.testProgramSize("^", 3);
+ ApiTestUtils.testProgramSize("^$", 4);
+ ApiTestUtils.testProgramSize("a+b", 5);
+ ApiTestUtils.testProgramSize("a+b?", 6);
+ ApiTestUtils.testProgramSize("(a+b)", 7);
+ ApiTestUtils.testProgramSize("a+b.*", 7);
+ ApiTestUtils.testProgramSize("(a+b?)", 8);
+ }
+
@Test
public void testGroupCount() {
- // It is a simple delegation, but still test it.
ApiTestUtils.testGroupCount("(.*)ab(.*)a", 2);
ApiTestUtils.testGroupCount("(.*)(ab)(.*)a", 3);
ApiTestUtils.testGroupCount("(.*)((a)b)(.*)a", 4);
@@ -176,6 +188,8 @@ public class PatternTest {
@Test
public void testNamedGroups() {
+ assertNamedGroupsEquals(ImmutableMap.of("foo", 1), "(?P<foo>\\d{2})");
+ assertNamedGroupsEquals(Collections.<String, Integer>emptyMap(), "\\d{2}");
assertNamedGroupsEquals(Collections.<String, Integer>emptyMap(), "hello");
assertNamedGroupsEquals(Collections.<String, Integer>emptyMap(), "(.*)");
assertNamedGroupsEquals(ImmutableMap.of("any", 1), "(?P<any>.*)");
=====================================
javatests/com/google/re2j/RE2CompileTest.java
=====================================
@@ -67,7 +67,7 @@ public class RE2CompileTest {
@Test
public void testCompile() {
try {
- RE2.compile(input);
+ RE2 unused = RE2.compile(input);
if (expectedError != null) {
fail("RE2.compile(" + input + ") was successful, expected " + expectedError);
}
=====================================
javatests/com/google/re2j/RE2Test.java
=====================================
@@ -9,13 +9,16 @@
package com.google.re2j;
-import java.util.Arrays;
-import org.junit.Test;
-
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.util.Arrays;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
/** Tests of RE2 API. */
+ at RunWith(JUnit4.class)
public class RE2Test {
@Test
public void testFullMatch() {
=====================================
javatests/com/google/re2j/UnicodeTest.java
=====================================
@@ -6,10 +6,15 @@
*/
package com.google.re2j;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
+import java.util.ArrayList;
+import java.util.List;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+ at RunWith(JUnit4.class)
public class UnicodeTest {
@Test
@@ -29,6 +34,56 @@ public class UnicodeTest {
}
}
+ @Test
+ public void testEqualsIgnoreCase() {
+ List<EqualsIgnoreCaseTest> testCases = new ArrayList<EqualsIgnoreCaseTest>();
+
+ for (int r = 'a'; r <= 'z'; r++) {
+ int u = r - ('a' - 'A');
+ testCases.add(new EqualsIgnoreCaseTest(r, r, true));
+ testCases.add(new EqualsIgnoreCaseTest(u, u, true));
+ testCases.add(new EqualsIgnoreCaseTest(r, u, true));
+ testCases.add(new EqualsIgnoreCaseTest(u, r, true));
+ }
+
+ testCases.add(new EqualsIgnoreCaseTest('{', '{', true));
+ testCases.add(new EqualsIgnoreCaseTest('é', 'É', true));
+ testCases.add(new EqualsIgnoreCaseTest('Ú', 'ú', true));
+ testCases.add(new EqualsIgnoreCaseTest('\u212A', 'K', true));
+ testCases.add(new EqualsIgnoreCaseTest('\u212A', 'k', true));
+
+ testCases.add(new EqualsIgnoreCaseTest('\u212A', 'a', false));
+ testCases.add(new EqualsIgnoreCaseTest('ü', 'ű', false));
+ testCases.add(new EqualsIgnoreCaseTest('b', 'k', false));
+ testCases.add(new EqualsIgnoreCaseTest('C', 'x', false));
+ testCases.add(new EqualsIgnoreCaseTest('/', '_', false));
+ testCases.add(new EqualsIgnoreCaseTest('d', ')', false));
+ testCases.add(new EqualsIgnoreCaseTest('@', '`', false));
+
+ for (EqualsIgnoreCaseTest testCase : testCases) {
+ boolean equals = Unicode.equalsIgnoreCase(testCase.r1, testCase.r2);
+
+ if (testCase.shouldMatch) {
+ assertTrue((char) testCase.r1 + " should be equal to " + (char) testCase.r2, equals);
+ } else {
+ assertFalse((char) testCase.r1 + " should not be equal to " + (char) testCase.r2, equals);
+ }
+ }
+ }
+
+ // EqualsIgnoreCaseTest wraps test case parameters for testEqualsIgnoreCase().
+ private static class EqualsIgnoreCaseTest {
+ private final int r1;
+ private final int r2;
+ private final boolean shouldMatch;
+
+ public EqualsIgnoreCaseTest(int r1, int r2, boolean shouldMatch) {
+ this.r1 = r1;
+ this.r2 = r2;
+ this.shouldMatch = shouldMatch;
+ }
+ }
+
// TODO(adonovan): tests for:
//
// boolean isUpper(int r);
View it on GitLab: https://salsa.debian.org/java-team/re2j/-/compare/2cbd64a9a56afed1ee72712ece02b546f50997b9...daa0f70f1014c0f8d8f29eca6f68d42d8f9ce9c0
--
View it on GitLab: https://salsa.debian.org/java-team/re2j/-/compare/2cbd64a9a56afed1ee72712ece02b546f50997b9...daa0f70f1014c0f8d8f29eca6f68d42d8f9ce9c0
You're receiving this email because of your account on salsa.debian.org. Manage all notifications: https://salsa.debian.org/-/profile/notifications | Help: https://salsa.debian.org/help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20261113/ea6190ac/attachment.htm>
More information about the pkg-java-commits
mailing list