コード例 #1
0
        public static string GetWorldName(string worldFile)
        {
            if (string.IsNullOrEmpty(worldFile))
            {
                throw new ArgumentException("worldFile is null or empty");
            }

            if (!SCommon.StartsWithIgnoreCase(worldFile, WORLD_FILE_PREFIX))
            {
                throw new ArgumentException("Bad worldFile_1");
            }

            worldFile = worldFile.Substring(WORLD_FILE_PREFIX.Length);

            if (!SCommon.EndsWithIgnoreCase(worldFile, WORLD_FILE_SUFFIX))
            {
                throw new ArgumentException("Bad worldFile_2");
            }

            worldFile = worldFile.Substring(0, worldFile.Length - WORLD_FILE_SUFFIX.Length);

            if (worldFile == "")
            {
                throw new ArgumentException("Bad worldFile_3");
            }

            return(worldFile);            // as worldName
        }
コード例 #2
0
        /// <summary>
        /// マップファイル名からマップ名を得る。
        /// 失敗すると、デフォルトのマップ名を返す。
        /// </summary>
        /// <param name="mapFile">マップファイル名</param>
        /// <param name="defval">デフォルトのマップ名</param>
        /// <returns>マップ名</returns>
        public static string GetMapName(string mapFile, string defval)
        {
            if (!SCommon.StartsWithIgnoreCase(mapFile, MAP_FILE_PREFIX))
            {
                return(defval);
            }

            mapFile = mapFile.Substring(MAP_FILE_PREFIX.Length);

            if (!SCommon.EndsWithIgnoreCase(mapFile, MAP_FILE_SUFFIX))
            {
                return(defval);
            }

            mapFile = mapFile.Substring(0, mapFile.Length - MAP_FILE_SUFFIX.Length);

            if (mapFile == "")
            {
                return(defval);
            }

            return(mapFile);            // as mapName
        }