001package votorola.g.web.gwt; // Copyright 2012, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. 002 003import java.util.regex.MatchResult; 004 005 006/** A partial implementation of match result that never sets an empty string for a group 007 * value in lieu of a null value. This is intended to eliminate client variance in cases 008 * where an empty string is not expected in the result. For example, {@linkplain 009 * com.google.gwt.regexp.shared.MatchResult#getGroup(int) GWT's API} says, "If the given 010 * group was optional and did not match, the behavior is browser-dependent". 011 */ 012public final class MatchResultNE implements MatchResult 013{ 014 015 016 /** Constructs a MatchResultNE. 017 */ 018 public MatchResultNE( com.google.gwt.regexp.shared.MatchResult _m ) { m = _m; } 019 020 021 022 // - M a t c h - R e s u l t ---------------------------------------------------------- 023 024 025 public int end() { return start() + group().length(); } 026 027 028 029 /** Throws {@linkplain UnsupportedOperationException UnsupportedOperationException}. 030 */ 031 public int end( int g ) { throw new UnsupportedOperationException(); } 032 033 034 035 public String group() { return m.getGroup( 0 ); } 036 037 038 039 public String group( int g ) 040 { 041 String s = m.getGroup( g ); 042 if( g > 0 && s != null && s.length() == 0 ) s = null; 043 return s; 044 } 045 046 047 048 public int groupCount() { return m.getGroupCount() - 1; } 049 050 051 052 public int start() { return m.getIndex(); } 053 054 055 056 /** Throws {@linkplain UnsupportedOperationException UnsupportedOperationException}. 057 */ 058 public int start( int g ) { throw new UnsupportedOperationException(); } 059 060 061 062//// P r i v a t e /////////////////////////////////////////////////////////////////////// 063 064 065 private final com.google.gwt.regexp.shared.MatchResult m; 066 067 068}