private static bool IsValidWindowsNameCore( Substring fileName )
        {
            Substring trimmedFileName = fileName.TrimEnd();

            // may not end in period on windows
            // (even if period is followed by whitespaces)
            if( trimmedFileName[fileName.Length - 1] == '.' )
                return false;

            // current and parent directory names
            // the step above accounts for this
            /*if( trimmedFileName.Equals(".", CompareOptions.Ordinal)
             || trimmedFileName.Equals("..", CompareOptions.Ordinal) )
                return false;*/

            // DOS device names, in any character case
            foreach( var dosDevName in DosDeviceNames )
            {
                if( fileName.Equals(dosDevName, CompareOptions.OrdinalIgnoreCase) )
                    return false;
            }

            // DOS device names plus any extension
            int extensionAt = fileName.LastIndexOf('.'); // this would not be OK, if we were checking file paths, instead of file names!
            if( extensionAt != -1 )
            {
                fileName = fileName.Substr(startIndex: 0, length: extensionAt);
                foreach( var dosDevName in DosDeviceNames )
                {
                    if( fileName.Equals(dosDevName, CompareOptions.OrdinalIgnoreCase) )
                        return false;
                }
            }

            return true;
        }
Example #2
0
        private Substring FromCsvString( Substring substr )
        {
            if( substr.Length == 0
             || substr.Equals("\"\"", CompareOptions.Ordinal, CultureInfo.InvariantCulture) )
                return Substring.Empty;

            if( substr[0] == '"'
             && substr[substr.Length - 1] == '"' )
                return substr.Substr(1, substr.Length - 2).ToString().Replace("\"\"", "\"");
            else
                return substr;
        }