From da9f5e91982a890fbe49b5ca9de17f5cc1214017 Mon Sep 17 00:00:00 2001 From: Vlasislav Kashin <99754299+vloldik@users.noreply.github.com> Date: Sun, 13 Jul 2025 17:50:43 +0300 Subject: [PATCH] Add copyright header --- build/rust_build.rs | 85 +++---------------- src/generated/metadata/mod.rs | 16 ++++ src/generated/mod.rs | 15 ++++ src/interfaces/mod.rs | 16 +++- src/lib.rs | 15 ++++ src/macros/mod.rs | 14 +++ src/phonenumberutil/comparisons.rs | 0 src/phonenumberutil/enums.rs | 15 ++++ src/phonenumberutil/errors.rs | 15 ++++ src/phonenumberutil/helper_constants.rs | 16 ++++ src/phonenumberutil/helper_functions.rs | 15 ++++ src/phonenumberutil/helper_types.rs | 16 ++++ src/phonenumberutil/mod.rs | 16 +++- .../phone_number_regexps_and_mappings.rs | 16 ++++ src/regex_based_matcher.rs | 16 ++++ src/regex_util.rs | 15 ++++ src/regexp_cache.rs | 15 ++++ src/region_code.rs | 15 ++++ src/string_util.rs | 15 ++++ 19 files changed, 273 insertions(+), 73 deletions(-) delete mode 100644 src/phonenumberutil/comparisons.rs diff --git a/build/rust_build.rs b/build/rust_build.rs index 891fcf7..1ba5937 100644 --- a/build/rust_build.rs +++ b/build/rust_build.rs @@ -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) -> 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() diff --git a/src/generated/metadata/mod.rs b/src/generated/metadata/mod.rs index 32b0d34..f886b23 100644 --- a/src/generated/metadata/mod.rs +++ b/src/generated/metadata/mod.rs @@ -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; diff --git a/src/generated/mod.rs b/src/generated/mod.rs index b186c5f..3cad8c1 100644 --- a/src/generated/mod.rs +++ b/src/generated/mod.rs @@ -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; diff --git a/src/interfaces/mod.rs b/src/interfaces/mod.rs index debf76d..14abd41 100644 --- a/src/interfaces/mod.rs +++ b/src/interfaces/mod.rs @@ -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 diff --git a/src/lib.rs b/src/lib.rs index da5df02..7d3d667 100644 --- a/src/lib.rs +++ b/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; diff --git a/src/macros/mod.rs b/src/macros/mod.rs index 64ad470..fb36b18 100644 --- a/src/macros/mod.rs +++ b/src/macros/mod.rs @@ -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 diff --git a/src/phonenumberutil/comparisons.rs b/src/phonenumberutil/comparisons.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/phonenumberutil/enums.rs b/src/phonenumberutil/enums.rs index bf92e16..ef00b48 100644 --- a/src/phonenumberutil/enums.rs +++ b/src/phonenumberutil/enums.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. + use strum::EnumIter; /// INTERNATIONAL and NATIONAL formats are consistent with the definition diff --git a/src/phonenumberutil/errors.rs b/src/phonenumberutil/errors.rs index 5037246..c823eb3 100644 --- a/src/phonenumberutil/errors.rs +++ b/src/phonenumberutil/errors.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. + use std::num::ParseIntError; use thiserror::Error; diff --git a/src/phonenumberutil/helper_constants.rs b/src/phonenumberutil/helper_constants.rs index f3fa837..0f91383 100644 --- a/src/phonenumberutil/helper_constants.rs +++ b/src/phonenumberutil/helper_constants.rs @@ -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 diff --git a/src/phonenumberutil/helper_functions.rs b/src/phonenumberutil/helper_functions.rs index 64371bb..80ed092 100644 --- a/src/phonenumberutil/helper_functions.rs +++ b/src/phonenumberutil/helper_functions.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. + use std::collections::{HashMap, HashSet}; use protobuf::Message; diff --git a/src/phonenumberutil/helper_types.rs b/src/phonenumberutil/helper_types.rs index caa7e7b..ac679cb 100644 --- a/src/phonenumberutil/helper_types.rs +++ b/src/phonenumberutil/helper_types.rs @@ -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; diff --git a/src/phonenumberutil/mod.rs b/src/phonenumberutil/mod.rs index 0938357..aa08db8 100644 --- a/src/phonenumberutil/mod.rs +++ b/src/phonenumberutil/mod.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 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; diff --git a/src/phonenumberutil/phone_number_regexps_and_mappings.rs b/src/phonenumberutil/phone_number_regexps_and_mappings.rs index 2e15d93..7986d4c 100644 --- a/src/phonenumberutil/phone_number_regexps_and_mappings.rs +++ b/src/phonenumberutil/phone_number_regexps_and_mappings.rs @@ -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; diff --git a/src/regex_based_matcher.rs b/src/regex_based_matcher.rs index fcd9e12..8b631b5 100644 --- a/src/regex_based_matcher.rs +++ b/src/regex_based_matcher.rs @@ -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}; diff --git a/src/regex_util.rs b/src/regex_util.rs index 0d6e9d8..b6b9918 100644 --- a/src/regex_util.rs +++ b/src/regex_util.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. + use regex::{Captures, Match, Regex}; pub trait RegexFullMatch { diff --git a/src/regexp_cache.rs b/src/regexp_cache.rs index 8828b45..a04d6cb 100644 --- a/src/regexp_cache.rs +++ b/src/regexp_cache.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. + use std::sync::Arc; use dashmap::DashMap; diff --git a/src/region_code.rs b/src/region_code.rs index df5fde4..f85fd3e 100644 --- a/src/region_code.rs +++ b/src/region_code.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. + pub struct RegionCode { } diff --git a/src/string_util.rs b/src/string_util.rs index a7bcaa5..37e8da5 100644 --- a/src/string_util.rs +++ b/src/string_util.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. + use std::borrow::Cow; /// Strips prefix of given string Cow. Returns option with `Some` if