unsafe private static int internalGetCodePageFromName(String name) {
int left = 0;
int right = lastEncodingItem;
int index;
int result;
//Binary search the array until we have only a couple of elements left and then
//just walk those elements.
while ((right - left)>3) {
index = ((right - left)/2) + left;
bool success;
result = String.nativeCompareOrdinalWC(name, encodingDataPtr[index].webName, true, out success);
if (result == 0) {
//We found the item, return the associated codepage.
return (encodingDataPtr[index].codePage);
} else if (result<0) {
//The name that we're looking for is less than our current index.
right = index;
} else {
//The name that we're looking for is greater than our current index
left = index;
}
}
//Walk the remaining elements (it'll be 3 or fewer).
for (; left<=right; left++) {
bool success;
if (String.nativeCompareOrdinalWC(name, encodingDataPtr[left].webName, true,out success)==0) {
return (encodingDataPtr[left].codePage);
}
}
// The encoding name is not valid.
throw new ArgumentException(
String.Format(
CultureInfo.CurrentCulture,
Environment.GetResourceString("Argument_EncodingNotSupported"), name), "name");
}