comparison src/luan/modules/RegexLuan.java @ 1897:8ed184a0cde2

regex and swing
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 14 Apr 2025 12:46:45 -0600
parents e59349d53fec
children aa24812aaf98
comparison
equal deleted inserted replaced
1896:1cd29d57c9c1 1897:8ed184a0cde2
1 package luan.modules; 1 package luan.modules;
2 2
3 import java.util.regex.Pattern; 3 import java.util.regex.Pattern;
4 import java.util.regex.Matcher; 4 import java.util.regex.Matcher;
5 import java.util.regex.PatternSyntaxException;
5 import luan.Luan; 6 import luan.Luan;
6 import luan.LuanMutable; 7 import luan.LuanMutable;
7 import luan.LuanTable; 8 import luan.LuanTable;
8 import luan.LuanFunction; 9 import luan.LuanFunction;
9 import luan.LuanException; 10 import luan.LuanException;
11 12
12 public final class RegexLuan implements LuanMutable { 13 public final class RegexLuan implements LuanMutable {
13 public Pattern pattern; 14 public Pattern pattern;
14 private boolean immutable = false; 15 private boolean immutable = false;
15 16
16 public RegexLuan(String s) { 17 public RegexLuan(String s) throws LuanException {
17 this.pattern = Pattern.compile(s); 18 try {
19 this.pattern = Pattern.compile(s);
20 } catch(java.util.regex.PatternSyntaxException e) {
21 throw new LuanException(e.getMessage(),e);
22 }
18 } 23 }
19 24
20 @Override public boolean isImmutable() { 25 @Override public boolean isImmutable() {
21 return immutable; 26 return immutable;
22 } 27 }
39 if( !m.find(start) ) 44 if( !m.find(start) )
40 return null; 45 return null;
41 int n = m.groupCount(); 46 int n = m.groupCount();
42 Object[] rtn = new Object[2+n]; 47 Object[] rtn = new Object[2+n];
43 rtn[0] = m.start() + 1; 48 rtn[0] = m.start() + 1;
44 rtn[1] = m.end(); 49 rtn[1] = m.end() + 1;
45 for( int i=0; i<n; i++ ) { 50 for( int i=0; i<n; i++ ) {
46 rtn[2+i] = m.group(i+1); 51 rtn[2+i] = m.group(i+1);
47 } 52 }
48 return rtn; 53 return rtn;
49 } 54 }