From ddf696e1e405c59788176c053222b6b2065d7d4f Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Sat, 4 Jul 2015 11:03:00 +0200 Subject: [PATCH] README: Use syntax highlighting for code blocks --- README.md | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index ba59dc5b8..088ddca6d 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,13 @@ Google's common Java, C++ and JavaScript library for parsing, formatting, storin # Highlights of functionality * Parsing/formatting/validating phone numbers for all countries/regions of the world. - * getNumberType - gets the type of the number based on the number itself; able to distinguish Fixed-line, Mobile, Toll-free, Premium Rate, Shared Cost, VoIP and Personal Numbers (whenever feasible). - * isNumberMatch - gets a confidence level on whether two numbers could be the same. - * getExampleNumber/getExampleNumberByType - provides valid example numbers for all countries/regions, with the option of specifying which type of example phone number is needed. - * isPossibleNumber - quickly guessing whether a number is a possible phonenumber by using only the length information, much faster than a full validation. - * isValidNumber - full validation of a phone number for a region using length and prefix information. + * ` getNumberType ` - gets the type of the number based on the number itself; able to distinguish Fixed-line, Mobile, Toll-free, Premium Rate, Shared Cost, VoIP and Personal Numbers (whenever feasible). + * ` isNumberMatch ` - gets a confidence level on whether two numbers could be the same. + * ` getExampleNumber `/` getExampleNumberByType ` - provides valid example numbers for all countries/regions, with the option of specifying which type of example phone number is needed. + * ` isPossibleNumber ` - quickly guessing whether a number is a possible phonenumber by using only the length information, much faster than a full validation. + * ` isValidNumber ` - full validation of a phone number for a region using length and prefix information. * ` AsYouTypeFormatter ` - formats phone numbers on-the-fly when users enter each digit. - * findNumbers - finds numbers in text input. + * ` findNumbers ` - finds numbers in text input. * ` PhoneNumberOfflineGeocoder ` - provides geographical information related to a phone number. * ` PhoneNumberToCarrierMapper ` - provides carrier information related to a phone number. @@ -26,7 +26,8 @@ http://repo1.maven.org/maven2/com/googlecode/libphonenumber/libphonenumber/ # Quick Examples Let's say you have a string representing a phone number from Switzerland. This is how you parse/normalize it into a ` PhoneNumber ` object: -``` + +```java String swissNumberStr = "044 668 18 00" PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); try { @@ -37,22 +38,22 @@ try { ``` At this point, swissNumberProto contains: -``` +```json { -country_code: 41 -national_number: 446681800 + "country_code": 41, + "national_number": 446681800 } ``` ` PhoneNumber ` is a class that is auto-generated from the phonenumber.proto with necessary modifications for efficiency. For details on the meaning of each field, refer to https://github.com/googlei18n/test/blob/master/resources/phonenumber.proto Now let us validate whether the number is valid: -``` +```java boolean isValid = phoneUtil.isValidNumber(swissNumberProto); // returns true ``` There are a few formats supported by the formatting method, as illustrated below: -``` +```java // Produces "+41 44 668 18 00" System.out.println(phoneUtil.format(swissNumberProto, PhoneNumberFormat.INTERNATIONAL)); // Produces "044 668 18 00" @@ -63,13 +64,13 @@ System.out.println(phoneUtil.format(swissNumberProto, PhoneNumberFormat.E164)); You could also choose to format the number in the way it is dialed from another country: -``` +```java // Produces "011 41 44 668 1800", the number when it is dialed in the United States. System.out.println(phoneUtil.formatOutOfCountryCallingNumber(swissNumberProto, "US")); ``` ### Formatting Phone Numbers 'as you type' -``` +```java PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); AsYouTypeFormatter formatter = phoneUtil.getAsYouTypeFormatter("US"); System.out.println(formatter.inputDigit('6')); // Outputs "6" @@ -78,7 +79,7 @@ System.out.println(formatter.inputDigit('3')); // Now outputs "650 253" ``` ### Geocoding Phone Numbers offline -``` +```java PhoneNumberOfflineGeocoder geocoder = PhoneNumberOfflineGeocoder.getInstance(); // Outputs "Zurich" System.out.println(geocoder.getDescriptionForNumber(swissNumberProto, Locale.ENGLISH)); @@ -89,7 +90,7 @@ System.out.println(geocoder.getDescriptionForNumber(swissNumberProto, Locale.ITA ``` ### Mapping Phone Numbers to carrier -``` +```java PhoneNumber swissMobileNumber = new PhoneNumber().setCountryCode(41).setNationalNumber(798765432L); PhoneNumberToCarrierMapper carrierMapper = PhoneNumberToCarrierMapper.getInstance();