Package findstruct.StructModel

Examples of findstruct.StructModel.Match


                    }
                }
            }
            // Here we've matched all subparts, sorted in matches
            Iterator<Match> it = matches.iterator();
            Match next = null;
            if (it.hasNext()) next = it.next();
            else {
                // No substructure matched. It's all text.
                addText(result,s,start,end);
                //result.addContent(s.substring(start, end).trim());
                return result;
            }
            Match curr = null;
            int used = start;
            do {
                curr = next;
                next = (it.hasNext())? it.next():null;
                if (used<curr.start) {
                    addText(result,s,used,curr.start);
                    //result.addContent(s.substring(used, curr.start).trim());
                    used = curr.start;
                } else if (used>curr.start) {
                    System.err.println("Overlapped matches among parts of "
                            +name+": "+used+" vs. "+curr.start);
                }
                SM mod = curr.matched;
                if (curr.matched.isPattern()) {
                    Element patElt = new Element(mod.name);
                    int nb = curr.numBindings();
                    if (nb<0) patElt.addContent(curr.vals.get(0));
                    else for (int i=0; i<nb; i++) {
                        patElt.addContent(curr.bindingToXML(i));
                    }
                    result.addContent(patElt);
                    used = curr.end;
                } else { // Start element, not pattern
                    used = curr.end;
View Full Code Here


                //System.out.println("Try pmatch pattern \""+pattern+"\" at "+start+"-"+end);
                Matcher m = pattern.matcher(s);
                m.region(start, end);
                while (m.find()) {
                    //System.out.println("Matched "+m.start()+"-"+m.end());
                    Match mtch = new Match(m.start(), m.end(), this);
                    if (bindings!=null) {
                        int gc = Math.min(m.groupCount(), bindings.length);
                        for (int i=1; i<=gc; i++) {
                            mtch.bind(bindings[i-1], m.group(i));
                        }
                    } else if (m.groupCount()>0) { // no explicit bindings; save group 1
                        mtch.bind(null,m.group(1));
                    }
                    alm.add(mtch);
                }
            } else {
                for (Pattern p: beg) {
                    //System.out.println("Try match \""+p+"\" at "+start+"-"+end);
                    Matcher m = p.matcher(s);
                    m.region(start, end);
                    // Find it only once: PE: ... Other PE: problem!
                    // Andreea Bodnari: we actually want to find the section
                    // if it is present multiple times
                    while (m.find()) {
                        //System.out.println("Matched "+m.start()+"-"+m.end());
                        Match mtch = new Match(m.start(), m.end(), this);
                        alm.add(mtch);
                    }
                }
            }
            return alm;
View Full Code Here

            return e;
        }
       
        public int compareTo(Object o) {
            if (o instanceof Match) {
                Match other = (Match) o;
                if (this.start<other.start) return -1;
                if (this.start>other.start) return 1;
                if (this.end<other.end) return -1;
                if (this.end>other.end) return 1;
                return 0;
View Full Code Here

TOP

Related Classes of findstruct.StructModel.Match

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.