Browse Source

JAVA/CPP: Better exclusion of dates, change in build error messages.

pull/567/head
Lara Scheidegger 12 years ago
committed by Mihaela Rosca
parent
commit
b1337c7ff1
7 changed files with 20 additions and 11 deletions
  1. +1
    -1
      cpp/src/phonenumbers/phonenumbermatcher.cc
  2. +4
    -2
      cpp/test/phonenumbers/phonenumbermatcher_test.cc
  3. +1
    -1
      java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberMatcher.java
  4. +4
    -0
      java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberMatcherTest.java
  5. +10
    -7
      tools/java/common/src/com/google/i18n/phonenumbers/BuildMetadataFromXml.java
  6. BIN
      tools/java/cpp-build/target/cpp-build-1.0-SNAPSHOT-jar-with-dependencies.jar
  7. BIN
      tools/java/java-build/target/java-build-1.0-SNAPSHOT-jar-with-dependencies.jar

+ 1
- 1
cpp/src/phonenumbers/phonenumbermatcher.cc View File

@ -305,7 +305,7 @@ class PhoneNumberMatcherRegExps : public Singleton<PhoneNumberMatcherRegExps> {
"(?:(?:[0-3]?\\d/[01]?\\d)|"
"(?:[01]?\\d/[0-3]?\\d))/(?:[12]\\d)?\\d{2}")),
time_stamps_(regexp_factory_->CreateRegExp(
"[12]\\d{3}[-/]?[01]\\d[-/]?[0-3]\\d [0-2]\\d$")),
"[12]\\d{3}[-/]?[01]\\d[-/]?[0-3]\\d +[0-2]\\d$")),
time_stamps_suffix_(regexp_factory_->CreateRegExp(":[0-5]\\d")),
matching_brackets_(regexp_factory_->CreateRegExp(
StrCat(leading_maybe_matched_bracket_, non_parens_, "+",


+ 4
- 2
cpp/test/phonenumbers/phonenumbermatcher_test.cc View File

@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// Author: Lara Rennie
#include "phonenumbers/phonenumbermatcher.h"
#include <string>
@ -811,6 +809,10 @@ static const NumberTest kImpossibleCases[] = {
NumberTest("2012-01-02 08:00", RegionCode::US()),
NumberTest("2012/01/02 08:00", RegionCode::US()),
NumberTest("20120102 08:00", RegionCode::US()),
NumberTest("2014-04-12 04:04 PM", RegionCode::US()),
NumberTest("2014-04-12 &nbsp;04:04 PM", RegionCode::US()),
NumberTest("2014-04-12 &nbsp;04:04 PM", RegionCode::US()),
NumberTest("2014-04-12 04:04 PM", RegionCode::US()),
};
// Strings with number-like things that should only be found under "possible".


+ 1
- 1
java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberMatcher.java View File

@ -78,7 +78,7 @@ final class PhoneNumberMatcher implements Iterator<PhoneNumberMatch> {
* trailing ":\d\d" -- that is covered by TIME_STAMPS_SUFFIX.
*/
private static final Pattern TIME_STAMPS =
Pattern.compile("[12]\\d{3}[-/]?[01]\\d[-/]?[0-3]\\d [0-2]\\d$");
Pattern.compile("[12]\\d{3}[-/]?[01]\\d[-/]?[0-3]\\d +[0-2]\\d$");
private static final Pattern TIME_STAMPS_SUFFIX = Pattern.compile(":[0-5]\\d");
/**


+ 4
- 0
java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberMatcherTest.java View File

@ -440,6 +440,10 @@ public class PhoneNumberMatcherTest extends TestMetadataTestCase {
new NumberTest("2012-01-02 08:00", RegionCode.US),
new NumberTest("2012/01/02 08:00", RegionCode.US),
new NumberTest("20120102 08:00", RegionCode.US),
new NumberTest("2014-04-12 04:04 PM", RegionCode.US),
new NumberTest("2014-04-12 &nbsp;04:04 PM", RegionCode.US),
new NumberTest("2014-04-12 &nbsp;04:04 PM", RegionCode.US),
new NumberTest("2014-04-12 04:04 PM", RegionCode.US),
};
/**


+ 10
- 7
tools/java/common/src/com/google/i18n/phonenumbers/BuildMetadataFromXml.java View File

@ -242,8 +242,9 @@ public class BuildMetadataFromXml {
LOGGER.log(Level.SEVERE,
"A maximum of one intlFormat pattern for a numberFormat element should be " +
"defined.");
throw new RuntimeException("Invalid number of intlFormat patterns for country: " +
metadata.getId());
String countryId = metadata.getId().length() > 0 ?
metadata.getId() : Integer.toString(metadata.getCountryCode());
throw new RuntimeException("Invalid number of intlFormat patterns for country: " + countryId);
} else if (intlFormatPattern.getLength() == 0) {
// Default to use the same as the national pattern if none is defined.
intlFormat.mergeFrom(nationalFormat);
@ -275,11 +276,13 @@ public class BuildMetadataFromXml {
format.setPattern(validateRE(numberFormatElement.getAttribute(PATTERN)));
NodeList formatPattern = numberFormatElement.getElementsByTagName(FORMAT);
if (formatPattern.getLength() != 1) {
LOGGER.log(Level.SEVERE,
"Only one format pattern for a numberFormat element should be defined.");
throw new RuntimeException("Invalid number of format patterns for country: " +
metadata.getId());
int numFormatPatterns = formatPattern.getLength();
if (numFormatPatterns != 1) {
LOGGER.log(Level.SEVERE, "One format pattern for a numberFormat element should be defined.");
String countryId = metadata.getId().length() > 0 ?
metadata.getId() : Integer.toString(metadata.getCountryCode());
throw new RuntimeException("Invalid number of format patterns (" + numFormatPatterns +
") for country: " + countryId);
}
format.setFormat(formatPattern.item(0).getFirstChild().getNodeValue());
}


BIN
tools/java/cpp-build/target/cpp-build-1.0-SNAPSHOT-jar-with-dependencies.jar View File


BIN
tools/java/java-build/target/java-build-1.0-SNAPSHOT-jar-with-dependencies.jar View File


Loading…
Cancel
Save