Fix bug in AsYouTypeFormatter where we hit a IndexOutOfBoundsException in its Java implementation when extracting the Chinese national prefix 17951 and didn't reset the format template / lastMatchPosition.
Includes corresponding changes for C++ and JavaScript as well to keep the implementations in sync. (C++ and JS didn't exhibit buggy behavior because the corresponding substring methods don't throw errors for invalid start positions.)
Bugfix for https://github.com/googlei18n/libphonenumber/issues/592