private void AssertParsable(String number) { Telephone telephone = this.parser.CreateTelephone(number); NUnit.Framework.Assert.IsNotNull(telephone, number); NUnit.Framework.Assert.IsFalse(Ca.Infoway.Messagebuilder.StringUtils.IsBlank(telephone.Hl7FormattedPhoneNumber), number); }
private Telephone ProcessNumericNumber(String telephoneNumber) { Telephone telephone = new Telephone(); switch (telephoneNumber.Length) { case 11: if ("1".Equals(Ca.Infoway.Messagebuilder.StringUtils.Substring(telephoneNumber, 0, 1))) { return(ProcessNumericNumber(Ca.Infoway.Messagebuilder.StringUtils.Substring( telephoneNumber, 1))); } else { return(null); } case 10: telephone.AreaCode = Ca.Infoway.Messagebuilder.StringUtils.Substring(telephoneNumber, 0, 3); telephoneNumber = Ca.Infoway.Messagebuilder.StringUtils.Substring(telephoneNumber, 3); { telephone.PhoneNumber = Ca.Infoway.Messagebuilder.Util.Telephone.TelephoneLocalNumber .Create(telephoneNumber); return(telephone); } case 7: telephone.PhoneNumber = Ca.Infoway.Messagebuilder.Util.Telephone.TelephoneLocalNumber .Create(telephoneNumber); return(telephone); default: return(null); } }
private void AssertNotParsable(String number) { Telephone telephone = this.parser.CreateTelephone(number); NUnit.Framework.Assert.IsNull(telephone, number); }
/* This is a bit dreadful, but it seems to work */ private Telephone ProcessFormattedTelephoneNumber(String telephoneNumber) { String areaCode = null; String extension = null; String firstPart = null; TelephoneLocalNumber number = null; bool bracket = false; bool invalid = false; bool extensionIndicator = false; bool firstTime = true; /* foreach */ foreach (String token in Tokenize(telephoneNumber)) { if (Ca.Infoway.Messagebuilder.StringUtils.IsBlank(token)) { // ignore it } else if ("(".Equals(token)) { if (bracket || areaCode != null || number != null) { invalid = true; break; } else { bracket = true; } } else if (")".Equals(token)) { if (bracket && areaCode != null) { bracket = false; } else { invalid = true; break; } } else if (IsExtensionIndicator(token)) { if (extension == null) { extensionIndicator = true; } else { invalid = true; break; } } else if (IsOnlyNumbers(token) && extensionIndicator) { extension = token; extensionIndicator = false; } else if (IsOnlyNumbers(token) && token.Length == 3 && bracket) { if (areaCode == null) { areaCode = token; } else { invalid = true; break; } } else if (IsOnlyNumbers(token) && token.Length == 3) { if (firstPart == null) { firstPart = token; } else if (areaCode == null) { areaCode = firstPart; firstPart = token; } else { invalid = true; break; } } else if (IsOnlyNumbers(token) && token.Length == 4) { if (firstPart == null) { invalid = true; break; } else { Telephone temp = ProcessNumericNumber(firstPart + token); number = temp.PhoneNumber; firstPart = null; } } else if (IsOnlyNumbers(token) && token.Length == 7) { if (firstPart != null) { if (areaCode == null) { areaCode = firstPart; firstPart = null; } else { invalid = true; break; } } Telephone temp_0 = ProcessNumericNumber(token); number = temp_0.PhoneNumber; } else if (IsPunctuation(token)) { // ignore it } else if ("1".Equals(token) && firstTime) { // ignore it } else { invalid = true; break; } if (!"+".Equals(token)) { firstTime = false; } } if (number != null && !bracket && !invalid && !extensionIndicator) { Telephone result = new Telephone(); result.AreaCode = areaCode; result.PhoneNumber = number; result.Extension = extension; return(result); } else { return(null); } }