[jruby-joni] 178/279: Update README.md

Hideki Yamane henrich at moszumanska.debian.org
Mon Nov 16 11:27:27 UTC 2015


This is an automated email from the git hooks/post-receive script.

henrich pushed a commit to branch debian/sid
in repository jruby-joni.

commit 5c2a2e72011a8aefb12a24e23b14413152e56996
Author: Marcin Mielżyński <lopx at gazeta.pl>
Date:   Thu Aug 1 19:54:48 2013 +0200

    Update README.md
---
 README.md | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/README.md b/README.md
index e5c5611..252a828 100644
--- a/README.md
+++ b/README.md
@@ -3,6 +3,63 @@ joni
 
 Java port of Oniguruma regexp library
 
+## Usage
+
+### Imports
+  ```java
+      import org.jcodings.specific.UTF8Encoding;
+      import org.joni.Matcher;
+      import org.joni.Option;
+      import org.joni.Regex;
+  ```
+
+### Matching
+
+  ```java
+      
+      byte[] pattern = "a*".getBytes();
+      byte[] str = "aaa".getBytes();
+
+      Regex regex = new Regex(pattern, 0, pattern.length, Option.NONE, UTF8Encoding.INSTANCE);
+      Matcher matcher = regex.matcher(str);
+      int result = matcher.search(0, str.length, Option.DEFAULT);
+  ```
+
+### Using captures
+
+  ```java
+    byte[] pattern = "(a*)".getBytes();
+    byte[] str = "aaa".getBytes();
+
+    Regex regex = new Regex(pattern, 0, pattern.length, Option.NONE, UTF8Encoding.INSTANCE);
+    Matcher matcher = regex.matcher(str);
+    int result = matcher.search(0, str.length, Option.DEFAULT);
+    if (result != -1) {
+        Region region = matcher.getEagerRegion();
+    }
+  ```
+
+### Using named caputures
+
+  ```java
+    byte[] pattern = "(?<name>a*)".getBytes();
+    byte[] str = "aaa".getBytes();
+
+    Regex regex = new Regex(pattern, 0, pattern.length, Option.NONE, UTF8Encoding.INSTANCE);
+    Matcher matcher = regex.matcher(str);
+    int result = matcher.search(0, str.length, Option.DEFAULT);
+    if (result != -1) {
+        Region region = matcher.getEagerRegion();
+        for (Iterator<NameEntry> entry = regex.namedBackrefIterator(); entry.hasNext();) {
+            NameEntry e = entry.next();
+            int number = e.getBackRefs()[0]; // can have many refs per name
+            // int begin = region.beg[number];
+            // int end = region.end[number];
+
+        }
+    }
+  ```
+
 ## License
 
 Joni is released under the [MIT License](http://www.opensource.org/licenses/MIT).

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jruby-joni.git



More information about the pkg-java-commits mailing list