Org.BouncyCastle.Asn1.DerPrintableString.IsPrintableString C# (CSharp) Méthode

IsPrintableString() public static méthode

public static IsPrintableString ( string str ) : bool
str string
Résultat bool
		public static bool IsPrintableString(
			string str)
		{
			foreach (char ch in str)
			{
				if (ch > 0x007f)
					return false;

				if (char.IsLetterOrDigit(ch))
					continue;

//				if (char.IsPunctuation(ch))
//					continue;

				switch (ch)
				{
					case ' ':
					case '\'':
					case '(':
					case ')':
					case '+':
					case '-':
					case '.':
					case ':':
					case '=':
					case '?':
					case '/':
					case ',':
						continue;
				}

				return false;
			}

			return true;
		}
	}

Usage Example

 public DerPrintableString(string str, bool validate)
 {
     if (str == null)
     {
         throw new ArgumentNullException("str");
     }
     if (validate && !DerPrintableString.IsPrintableString(str))
     {
         throw new ArgumentException("string contains illegal characters", "str");
     }
     this.str = str;
 }