for Push.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.Commons
|
||||
{
|
||||
public class EncodingUxer
|
||||
{
|
||||
#region 列挙体
|
||||
|
||||
public enum EncodingType
|
||||
{
|
||||
Utf8WithBom,
|
||||
Utf8WithoutBom,
|
||||
ShiftJIS
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static Encoding GetEncoding(EncodingType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case EncodingType.Utf8WithBom:
|
||||
return new UTF8Encoding(encoderShouldEmitUTF8Identifier: true); // BOMあり
|
||||
case EncodingType.Utf8WithoutBom:
|
||||
return new UTF8Encoding(encoderShouldEmitUTF8Identifier: false); // BOMなし
|
||||
case EncodingType.ShiftJIS:
|
||||
return Encoding.GetEncoding("shift_jis"); // ANSI(Windows-932)
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(type), "未対応のエンコーディングです");
|
||||
}
|
||||
}
|
||||
|
||||
public static EncodingType? GetEncodingType(string typeString)
|
||||
{
|
||||
typeString = typeString.ToLower();
|
||||
|
||||
if (StringUxer.WildcardMatch(typeString, "*utf*8*without*bom*"))
|
||||
return EncodingType.Utf8WithoutBom;
|
||||
if (StringUxer.WildcardMatch(typeString, "*utf*8*with*bom*"))
|
||||
return EncodingType.Utf8WithBom;
|
||||
if (StringUxer.WildcardMatch(typeString, "*utf*8*"))
|
||||
return EncodingType.Utf8WithoutBom;
|
||||
if (StringUxer.WildcardMatch(typeString, "*s*jis*"))
|
||||
return EncodingType.ShiftJIS;
|
||||
if (StringUxer.WildcardMatch(typeString, "*シ*jis*"))
|
||||
return EncodingType.ShiftJIS;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user