public static bool IsValidLanguageID( char[] value, int startPos, int length ) {
int len = length;
if ( len < 2 ) {
return false;
}
bool fSeenLetter = false;
int i = startPos;
XmlCharType xmlCharType = XmlCharType.Instance;
char ch = value[i];
if ( xmlCharType.IsLetter(ch) ) {
if ( xmlCharType.IsLetter( value[++i] ) ) {
if ( len == 2 ) {
return true;
}
len--;
i++;
}
else if ( ('I' != ch && 'i' != ch ) && ( 'X' != ch && 'x' != ch ) ) { //IANA or custom Code
return false;
}
if ( value[i] != '-' ) {
return false;
}
len -= 2;
while ( len-- > 0 ) {
ch = value[++i];
if ( xmlCharType.IsLetter( ch ) ) {
fSeenLetter = true;
}
else if ( ch == '-' && fSeenLetter ) {
fSeenLetter = false;
}
else {
return false;
}
}
if ( fSeenLetter ) {
return true;
}
}
return false;
}
}