Browse Source

CPP: Small code tidy-ups (adding includes etc).

pull/567/head
Lara Scheidegger 15 years ago
committed by Mihaela Rosca
parent
commit
53ebe98c49
5 changed files with 18 additions and 11 deletions
  1. +9
    -3
      cpp/src/phonenumberutil.cc
  2. +4
    -5
      cpp/src/phonenumberutil_test.cc
  3. +2
    -1
      cpp/src/regexp_adapter.h
  4. +2
    -1
      cpp/src/regexp_adapter_test.cc
  5. +1
    -1
      cpp/src/regexp_cache_test.cc

+ 9
- 3
cpp/src/phonenumberutil.cc View File

@ -18,10 +18,14 @@
#include "phonenumberutil.h"
#include <algorithm>
#include <cctype>
#include <cstddef>
#include <fstream>
#include <iostream>
#include <iterator>
#include <map>
#include <sstream>
#include <utility>
#include <vector>
#include <google/protobuf/message_lite.h>
@ -786,11 +790,13 @@ bool PhoneNumberUtil::IsValidRegionCode(const string& region_code) const {
}
bool PhoneNumberUtil::HasValidRegionCode(const string& region_code,
int country_code,
int country_calling_code,
const string& number) const {
if (!IsValidRegionCode(region_code)) {
logger->Info(string("Number ") + number +
" has invalid or missing country code (" + country_code + ")");
" has invalid or missing country code (" +
country_calling_code +
")");
return false;
}
return true;
@ -1237,7 +1243,7 @@ void PhoneNumberUtil::GetRegionCodeForCountryCode(
list<string> region_codes;
GetRegionCodesForCountryCallingCode(country_calling_code, &region_codes);
*region_code = region_codes.size() != 0 ? region_codes.front() : "ZZ";
*region_code = (region_codes.size() > 0) ? region_codes.front() : "ZZ";
}
void PhoneNumberUtil::GetRegionCodeForNumber(const PhoneNumber& number,


+ 4
- 5
cpp/src/phonenumberutil_test.cc View File

@ -142,6 +142,9 @@ class RegionCode {
class PhoneNumberUtilTest : public testing::Test {
protected:
PhoneNumberUtilTest() : phone_util_(*PhoneNumberUtil::GetInstance()) {
}
// Wrapper functions for private functions that we want to test.
const PhoneMetadata* GetPhoneMetadata(const string& region_code) const {
return phone_util_.GetMetadataForRegion(region_code);
@ -211,7 +214,7 @@ class PhoneNumberUtilTest : public testing::Test {
return ExactlySameAs(expected_number, actual_number);
}
PhoneNumberUtil phone_util_;
const PhoneNumberUtil& phone_util_;
};
// Provides PhoneNumber comparison operators to support the use of EXPECT_EQ and
@ -248,10 +251,6 @@ ostream& operator<<(ostream& os, const PhoneNumber& number) {
return os;
}
TEST_F(PhoneNumberUtilTest, GetInstance) {
EXPECT_FALSE(PhoneNumberUtil::GetInstance() == NULL);
}
TEST_F(PhoneNumberUtilTest, GetSupportedRegions) {
set<string> regions;


+ 2
- 1
cpp/src/regexp_adapter.h View File

@ -14,7 +14,7 @@
// Author: George Yakovlev
// Philippe Liard
//
// Regexp adapter to allow a pluggable regexp engine. It has been introduced
// during the integration of the open-source version of this library into
// Chromium to be able to use the ICU Regex engine instead of RE2, which is not
@ -25,6 +25,7 @@
#ifndef I18N_PHONENUMBERS_REGEXP_ADAPTER_H_
#define I18N_PHONENUMBERS_REGEXP_ADAPTER_H_
#include <cstddef>
#include <string>
namespace i18n {


+ 2
- 1
cpp/src/regexp_adapter_test.cc View File

@ -15,12 +15,13 @@
// Author: George Yakovlev
// Philippe Liard
#include "regexp_adapter.h"
#include <string>
#include <gtest/gtest.h>
#include "base/scoped_ptr.h"
#include "regexp_adapter.h"
namespace i18n {
namespace phonenumbers {


+ 1
- 1
cpp/src/regexp_cache_test.cc View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// Author: Fredrik Roubert <roubert@google.com>
// Author: Fredrik Roubert
#include <cstddef>
#include <string>


Loading…
Cancel
Save