Add copyright header
This commit is contained in:
@@ -1,75 +1,18 @@
|
||||
// Copyright (C) 2009 The Libphonenumber Authors
|
||||
// Copyright (C) 2025 The Kashin Vladislav (Rust adaptation author)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/** TODO: uncomment, move to macros and refactor
|
||||
/**
|
||||
* This file represents content of https://github.com/google/libphonenumber/tree/master/tools/cpp
|
||||
*/
|
||||
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
enum BuildError {
|
||||
#[error("IO error occurred: {0}")]
|
||||
IO(#[from] std::io::Error),
|
||||
|
||||
#[error("Line {line_num} is too long (max is {max_len} bytes)")]
|
||||
LineTooLong { line_num: usize, max_len: usize },
|
||||
|
||||
#[error("Failed to parse prefix '{prefix}': {source}")]
|
||||
PrefixParseError {
|
||||
prefix: String,
|
||||
#[source]
|
||||
source: ParseIntError,
|
||||
},
|
||||
}
|
||||
|
||||
fn parse_prefixes(path: &str, prefixes: &mut BTreeMap<i32, String>) -> Result<(), BuildError> {
|
||||
prefixes.clear();
|
||||
|
||||
let input = File::open(path)?;
|
||||
const MAX_LINE_LENGTH: usize = 2 * 1024;
|
||||
|
||||
let mut reader = BufReader::new(input);
|
||||
let mut line_buffer = String::with_capacity(MAX_LINE_LENGTH);
|
||||
let mut line_number = 0;
|
||||
|
||||
loop {
|
||||
line_number += 1;
|
||||
line_buffer.clear();
|
||||
|
||||
let bytes_read = reader.read_line(&mut line_buffer)?;
|
||||
if bytes_read == 0 {
|
||||
break;
|
||||
}
|
||||
|
||||
if !line_buffer.ends_with('\n') {
|
||||
return Err(BuildError::LineTooLong {
|
||||
line_num: line_number,
|
||||
max_len: MAX_LINE_LENGTH,
|
||||
});
|
||||
}
|
||||
|
||||
let line = line_buffer.trim();
|
||||
if line.is_empty() || line.starts_with('#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some((prefix_str, desc)) = line.split_once('|') {
|
||||
if prefix_str.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let prefix_code = prefix_str.parse().map_err(|e| BuildError::PrefixParseError {
|
||||
prefix: prefix_str.to_string(),
|
||||
source: e,
|
||||
})?;
|
||||
prefixes.insert(prefix_code, desc.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
fn main() {
|
||||
protobuf_codegen::Codegen::new()
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
// Copyright (C) 2009 The Libphonenumber Authors
|
||||
// Copyright (C) 2025 The Kashin Vladislav (Rust adaptation author)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
mod metadata;
|
||||
mod test_metadata;
|
||||
|
||||
|
||||
@@ -1,2 +1,17 @@
|
||||
// Copyright (C) 2009 The Libphonenumber Authors
|
||||
// Copyright (C) 2025 The Kashin Vladislav (Rust adaptation author)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pub mod proto;
|
||||
pub mod metadata;
|
||||
|
||||
@@ -1,9 +1,23 @@
|
||||
// Copyright (C) 2009 The Libphonenumber Authors
|
||||
// Copyright (C) 2025 The Kashin Vladislav (Rust adaptation author)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::phonemetadata::PhoneNumberDesc;
|
||||
|
||||
/// Internal phonenumber matching API used to isolate the underlying
|
||||
/// implementation of the matcher and allow different implementations to be
|
||||
/// swapped in easily.
|
||||
|
||||
pub(crate) trait MatcherApi: Send + Sync {
|
||||
/// Returns whether the given national number (a string containing only decimal
|
||||
/// digits) matches the national number pattern defined in the given
|
||||
|
||||
15
src/lib.rs
15
src/lib.rs
@@ -1,3 +1,18 @@
|
||||
// Copyright (C) 2009 The Libphonenumber Authors
|
||||
// Copyright (C) 2025 The Kashin Vladislav (Rust adaptation author)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
mod interfaces;
|
||||
/// This module is automatically generated from /resources/*.proto
|
||||
mod generated;
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright (C) 2025 The Kashin Vladislav (Rust adaptation author)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// std::borrow::Cow
|
||||
// std::option::Option
|
||||
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
// Copyright (C) 2009 The Libphonenumber Authors
|
||||
// Copyright (C) 2025 The Kashin Vladislav (Rust adaptation author)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use strum::EnumIter;
|
||||
|
||||
/// INTERNATIONAL and NATIONAL formats are consistent with the definition
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
// Copyright (C) 2009 The Libphonenumber Authors
|
||||
// Copyright (C) 2025 The Kashin Vladislav (Rust adaptation author)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::num::ParseIntError;
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
// Copyright (C) 2009 The Libphonenumber Authors
|
||||
// Copyright (C) 2025 The Kashin Vladislav (Rust adaptation author)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
// The minimum and maximum length of the national significant number.
|
||||
pub const MIN_LENGTH_FOR_NSN: usize = 2;
|
||||
// The ITU says the maximum length should be 15, but we have found longer
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
// Copyright (C) 2009 The Libphonenumber Authors
|
||||
// Copyright (C) 2025 The Kashin Vladislav (Rust adaptation author)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use protobuf::Message;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
// Copyright (C) 2009 The Libphonenumber Authors
|
||||
// Copyright (C) 2025 The Kashin Vladislav (Rust adaptation author)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
use crate::phonenumber::phone_number::CountryCodeSource;
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
// Copyright (C) 2009 The Libphonenumber Authors
|
||||
// Copyright (C) 2025 The Kashin Vladislav (Rust adaptation author)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
mod helper_constants;
|
||||
mod helper_functions;
|
||||
pub mod errors;
|
||||
@@ -5,7 +20,6 @@ pub mod enums;
|
||||
pub mod phonenumberutil;
|
||||
mod phone_number_regexps_and_mappings;
|
||||
pub(self) mod helper_types;
|
||||
pub(self) mod comparisons;
|
||||
|
||||
use std::sync::LazyLock;
|
||||
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
// Copyright (C) 2009 The Libphonenumber Authors
|
||||
// Copyright (C) 2025 The Kashin Vladislav (Rust adaptation author)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use regex::Regex;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
// Copyright (C) 2009 The Libphonenumber Authors
|
||||
// Copyright (C) 2025 The Kashin Vladislav (Rust adaptation author)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
use log::{error};
|
||||
use super::regex_util::{RegexFullMatch, RegexConsume};
|
||||
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
// Copyright (C) 2009 The Libphonenumber Authors
|
||||
// Copyright (C) 2025 The Kashin Vladislav (Rust adaptation author)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use regex::{Captures, Match, Regex};
|
||||
|
||||
pub trait RegexFullMatch {
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
// Copyright (C) 2009 The Libphonenumber Authors
|
||||
// Copyright (C) 2025 The Kashin Vladislav (Rust adaptation author)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use dashmap::DashMap;
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
// Copyright (C) 2009 The Libphonenumber Authors
|
||||
// Copyright (C) 2025 The Kashin Vladislav (Rust adaptation author)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pub struct RegionCode {
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
// Copyright (C) 2009 The Libphonenumber Authors
|
||||
// Copyright (C) 2025 The Kashin Vladislav (Rust adaptation author)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
/// Strips prefix of given string Cow. Returns option with `Some` if
|
||||
|
||||
Reference in New Issue
Block a user