System.DateTimeParse.VerifyValidPunctuation C# (CSharp) Method

VerifyValidPunctuation() private static method

private static VerifyValidPunctuation ( __DTString &str ) : Boolean
str __DTString
return Boolean
        private static Boolean VerifyValidPunctuation(ref __DTString str) {
            // Compatability Behavior. Allow trailing nulls and surrounding hashes
            Char ch = str.Value[str.Index];
            if (ch == '#') {
                bool foundStart = false;
                bool foundEnd = false;
                for (int i = 0; i < str.len; i++) {
                    ch = str.Value[i];
                    if (ch == '#') {
                        if (foundStart) {
                            if (foundEnd) {
                                // Having more than two hashes is invalid
                                return false;
                            }
                            else {
                                foundEnd = true;
                            }
                        }
                        else {
                            foundStart = true;
                        }
                    }
                    else if (ch == '\0') {
                        // Allow nulls only at the end
                        if (!foundEnd) {
                            return false;
                        }
                    }
                    else if ((!Char.IsWhiteSpace(ch))) {
                        // Anthyhing other than whitespace outside hashes is invalid
                        if (!foundStart || foundEnd) {
                            return false;
                        }
                    }
                }
                if (!foundEnd) {
                    // The has was un-paired
                    return false;
                }
                // Valid Hash usage: eat the hash and continue. 
                str.GetNext();  
                return true;                                                                    
            }
            else if (ch == '\0') {
                for (int i = str.Index; i < str.len; i++) {
                    if (str.Value[i] != '\0') {
                        // Nulls are only valid if they are the only trailing character
                        return false;
                    }
                }
                // Move to the end of the string
                str.Index = str.len;
                return true;
            }
            return false;            
        }