private int matchXmlNamespaceAttribute ( String s ) { /* * The regex we're simulating is: "xmlns\\s*=\\s*\".+?\".*" */ StringPrefixSlicer stringSlicer = new StringPrefixSlicer ( s ) ; if ( stringSlicer . removePrefix ( "xmlns" ) == false ) return - 1 ; stringSlicer . removeRepeatingPrefix ( " " ) ; if ( stringSlicer . removePrefix ( "=" ) == false ) return - 1 ; stringSlicer . removeRepeatingPrefix ( " " ) ; if ( stringSlicer . removePrefix ( "\"" ) == false ) return - 1 ; if ( stringSlicer . removePrefixEndingWith ( "\"" ) == false ) return - 1 ; return s . length ( ) - stringSlicer . getString ( ) . length ( ) ; }
Checks if the string starts with a complete XML namespace attribute and if so returns the number of characters that match .