Add some phonenumberutil functions

This commit is contained in:
Vlasislav Kashin
2025-07-09 13:22:32 +03:00
parent 29f5e5664c
commit 7692433296
11 changed files with 1409 additions and 91 deletions

View File

@@ -1,3 +1,6 @@
use core::error;
use std::num::ParseIntError;
use thiserror::Error;
use crate::regexp_cache::ErrorInvalidRegex;
@@ -5,5 +8,38 @@ use crate::regexp_cache::ErrorInvalidRegex;
#[derive(Debug, PartialEq, Error)]
pub enum PhoneNumberUtilError {
#[error("{0}")]
InvalidRegexError(#[from] ErrorInvalidRegex)
}
InvalidRegexError(#[from] ErrorInvalidRegex),
#[error("Parse error: {0}")]
ParseError(#[from] ParseError),
#[error("Extract number error: {0}")]
ExtractNumberError(#[from] ExtractNumberError)
}
#[derive(Debug, PartialEq, Error)]
pub enum ParseError {
// Removed as OK variant
// NoParsingError,
#[error("Invalid country code")]
InvalidCountryCodeError, // INVALID_COUNTRY_CODE in the java version.
#[error("Not a number")]
NotANumber,
#[error("Too short after idd")]
TooShortAfterIdd,
#[error("Too short Nsn")]
TooShortNsn,
#[error("Too long nsn")]
TooLongNsn, // TOO_LONG in the java version.
#[error("{0}")]
InvalidRegexError(#[from] ErrorInvalidRegex),
#[error("{0}")]
ParseNumberAsIntError(#[from] ParseIntError)
}
#[derive(Debug, PartialEq, Error)]
pub enum ExtractNumberError {
#[error("No valid start character found")]
NoValidStartCharacter,
#[error("Invalid number")]
NotANumber,
}