mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
Fix IDE0066: Use switch expression
Only applied to where it doesn't look horrendous.
This commit is contained in:
parent
1d8bd96e86
commit
c2a74505a1
5 changed files with 88 additions and 206 deletions
|
|
@ -245,154 +245,67 @@ internal class SeStringEvaluator : IServiceType, ISeStringEvaluator
|
||||||
// if (context.HandlePayload(payload, in context))
|
// if (context.HandlePayload(payload, in context))
|
||||||
// return true;
|
// return true;
|
||||||
|
|
||||||
switch (payload.MacroCode)
|
return payload.MacroCode switch
|
||||||
{
|
{
|
||||||
case MacroCode.SetResetTime:
|
MacroCode.SetResetTime => this.TryResolveSetResetTime(in context, payload),
|
||||||
return this.TryResolveSetResetTime(in context, payload);
|
MacroCode.SetTime => this.TryResolveSetTime(in context, payload),
|
||||||
|
MacroCode.If => this.TryResolveIf(in context, payload),
|
||||||
case MacroCode.SetTime:
|
MacroCode.Switch => this.TryResolveSwitch(in context, payload),
|
||||||
return this.TryResolveSetTime(in context, payload);
|
MacroCode.SwitchPlatform => this.TryResolveSwitchPlatform(in context, payload),
|
||||||
|
MacroCode.PcName => this.TryResolvePcName(in context, payload),
|
||||||
case MacroCode.If:
|
MacroCode.IfPcGender => this.TryResolveIfPcGender(in context, payload),
|
||||||
return this.TryResolveIf(in context, payload);
|
MacroCode.IfPcName => this.TryResolveIfPcName(in context, payload),
|
||||||
|
// MacroCode.Josa
|
||||||
case MacroCode.Switch:
|
// MacroCode.Josaro
|
||||||
return this.TryResolveSwitch(in context, payload);
|
MacroCode.IfSelf => this.TryResolveIfSelf(in context, payload),
|
||||||
|
// MacroCode.NewLine (pass through)
|
||||||
case MacroCode.SwitchPlatform:
|
// MacroCode.Wait (pass through)
|
||||||
return this.TryResolveSwitchPlatform(in context, payload);
|
// MacroCode.Icon (pass through)
|
||||||
|
MacroCode.Color => this.TryResolveColor(in context, payload),
|
||||||
case MacroCode.PcName:
|
MacroCode.EdgeColor => this.TryResolveEdgeColor(in context, payload),
|
||||||
return this.TryResolvePcName(in context, payload);
|
MacroCode.ShadowColor => this.TryResolveShadowColor(in context, payload),
|
||||||
|
// MacroCode.SoftHyphen (pass through)
|
||||||
case MacroCode.IfPcGender:
|
// MacroCode.Key
|
||||||
return this.TryResolveIfPcGender(in context, payload);
|
// MacroCode.Scale
|
||||||
|
MacroCode.Bold => this.TryResolveBold(in context, payload),
|
||||||
case MacroCode.IfPcName:
|
MacroCode.Italic => this.TryResolveItalic(in context, payload),
|
||||||
return this.TryResolveIfPcName(in context, payload);
|
// MacroCode.Edge
|
||||||
|
// MacroCode.Shadow
|
||||||
// case MacroCode.Josa:
|
// MacroCode.NonBreakingSpace (pass through)
|
||||||
// case MacroCode.Josaro:
|
// MacroCode.Icon2 (pass through)
|
||||||
|
// MacroCode.Hyphen (pass through)
|
||||||
case MacroCode.IfSelf:
|
MacroCode.Num => this.TryResolveNum(in context, payload),
|
||||||
return this.TryResolveIfSelf(in context, payload);
|
MacroCode.Hex => this.TryResolveHex(in context, payload),
|
||||||
|
MacroCode.Kilo => this.TryResolveKilo(in context, payload),
|
||||||
// case MacroCode.NewLine: // pass through
|
// MacroCode.Byte
|
||||||
// case MacroCode.Wait: // pass through
|
MacroCode.Sec => this.TryResolveSec(in context, payload),
|
||||||
// case MacroCode.Icon: // pass through
|
// MacroCode.Time
|
||||||
|
MacroCode.Float => this.TryResolveFloat(in context, payload),
|
||||||
case MacroCode.Color:
|
// MacroCode.Link (pass through)
|
||||||
return this.TryResolveColor(in context, payload);
|
MacroCode.Sheet => this.TryResolveSheet(in context, payload),
|
||||||
|
MacroCode.SheetSub => this.TryResolveSheetSub(in context, payload),
|
||||||
case MacroCode.EdgeColor:
|
MacroCode.String => this.TryResolveString(in context, payload),
|
||||||
return this.TryResolveEdgeColor(in context, payload);
|
MacroCode.Caps => this.TryResolveCaps(in context, payload),
|
||||||
|
MacroCode.Head => this.TryResolveHead(in context, payload),
|
||||||
case MacroCode.ShadowColor:
|
MacroCode.Split => this.TryResolveSplit(in context, payload),
|
||||||
return this.TryResolveShadowColor(in context, payload);
|
MacroCode.HeadAll => this.TryResolveHeadAll(in context, payload),
|
||||||
|
MacroCode.Fixed => this.TryResolveFixed(in context, payload),
|
||||||
// case MacroCode.SoftHyphen: // pass through
|
MacroCode.Lower => this.TryResolveLower(in context, payload),
|
||||||
// case MacroCode.Key:
|
MacroCode.JaNoun => this.TryResolveNoun(ClientLanguage.Japanese, in context, payload),
|
||||||
// case MacroCode.Scale:
|
MacroCode.EnNoun => this.TryResolveNoun(ClientLanguage.English, in context, payload),
|
||||||
|
MacroCode.DeNoun => this.TryResolveNoun(ClientLanguage.German, in context, payload),
|
||||||
case MacroCode.Bold:
|
MacroCode.FrNoun => this.TryResolveNoun(ClientLanguage.French, in context, payload),
|
||||||
return this.TryResolveBold(in context, payload);
|
// MacroCode.ChNoun
|
||||||
|
MacroCode.LowerHead => this.TryResolveLowerHead(in context, payload),
|
||||||
case MacroCode.Italic:
|
MacroCode.ColorType => this.TryResolveColorType(in context, payload),
|
||||||
return this.TryResolveItalic(in context, payload);
|
MacroCode.EdgeColorType => this.TryResolveEdgeColorType(in context, payload),
|
||||||
|
// MacroCode.Ruby
|
||||||
// case MacroCode.Edge:
|
MacroCode.Digit => this.TryResolveDigit(in context, payload),
|
||||||
// case MacroCode.Shadow:
|
MacroCode.Ordinal => this.TryResolveOrdinal(in context, payload),
|
||||||
// case MacroCode.NonBreakingSpace: // pass through
|
// MacroCode.Sound (pass through)
|
||||||
// case MacroCode.Icon2: // pass through
|
MacroCode.LevelPos => this.TryResolveLevelPos(in context, payload),
|
||||||
// case MacroCode.Hyphen: // pass through
|
_ => false,
|
||||||
|
};
|
||||||
case MacroCode.Num:
|
|
||||||
return this.TryResolveNum(in context, payload);
|
|
||||||
|
|
||||||
case MacroCode.Hex:
|
|
||||||
return this.TryResolveHex(in context, payload);
|
|
||||||
|
|
||||||
case MacroCode.Kilo:
|
|
||||||
return this.TryResolveKilo(in context, payload);
|
|
||||||
|
|
||||||
// case MacroCode.Byte:
|
|
||||||
|
|
||||||
case MacroCode.Sec:
|
|
||||||
return this.TryResolveSec(in context, payload);
|
|
||||||
|
|
||||||
// case MacroCode.Time:
|
|
||||||
|
|
||||||
case MacroCode.Float:
|
|
||||||
return this.TryResolveFloat(in context, payload);
|
|
||||||
|
|
||||||
// case MacroCode.Link: // pass through
|
|
||||||
|
|
||||||
case MacroCode.Sheet:
|
|
||||||
return this.TryResolveSheet(in context, payload);
|
|
||||||
|
|
||||||
case MacroCode.SheetSub:
|
|
||||||
return this.TryResolveSheetSub(in context, payload);
|
|
||||||
|
|
||||||
case MacroCode.String:
|
|
||||||
return this.TryResolveString(in context, payload);
|
|
||||||
|
|
||||||
case MacroCode.Caps:
|
|
||||||
return this.TryResolveCaps(in context, payload);
|
|
||||||
|
|
||||||
case MacroCode.Head:
|
|
||||||
return this.TryResolveHead(in context, payload);
|
|
||||||
|
|
||||||
case MacroCode.Split:
|
|
||||||
return this.TryResolveSplit(in context, payload);
|
|
||||||
|
|
||||||
case MacroCode.HeadAll:
|
|
||||||
return this.TryResolveHeadAll(in context, payload);
|
|
||||||
|
|
||||||
case MacroCode.Fixed:
|
|
||||||
return this.TryResolveFixed(in context, payload);
|
|
||||||
|
|
||||||
case MacroCode.Lower:
|
|
||||||
return this.TryResolveLower(in context, payload);
|
|
||||||
|
|
||||||
case MacroCode.JaNoun:
|
|
||||||
return this.TryResolveNoun(ClientLanguage.Japanese, in context, payload);
|
|
||||||
|
|
||||||
case MacroCode.EnNoun:
|
|
||||||
return this.TryResolveNoun(ClientLanguage.English, in context, payload);
|
|
||||||
|
|
||||||
case MacroCode.DeNoun:
|
|
||||||
return this.TryResolveNoun(ClientLanguage.German, in context, payload);
|
|
||||||
|
|
||||||
case MacroCode.FrNoun:
|
|
||||||
return this.TryResolveNoun(ClientLanguage.French, in context, payload);
|
|
||||||
|
|
||||||
// case MacroCode.ChNoun:
|
|
||||||
|
|
||||||
case MacroCode.LowerHead:
|
|
||||||
return this.TryResolveLowerHead(in context, payload);
|
|
||||||
|
|
||||||
case MacroCode.ColorType:
|
|
||||||
return this.TryResolveColorType(in context, payload);
|
|
||||||
|
|
||||||
case MacroCode.EdgeColorType:
|
|
||||||
return this.TryResolveEdgeColorType(in context, payload);
|
|
||||||
|
|
||||||
// case MacroCode.Ruby:
|
|
||||||
|
|
||||||
case MacroCode.Digit:
|
|
||||||
return this.TryResolveDigit(in context, payload);
|
|
||||||
|
|
||||||
case MacroCode.Ordinal:
|
|
||||||
return this.TryResolveOrdinal(in context, payload);
|
|
||||||
|
|
||||||
// case MacroCode.Sound: // pass through
|
|
||||||
|
|
||||||
case MacroCode.LevelPos:
|
|
||||||
return this.TryResolveLevelPos(in context, payload);
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private unsafe bool TryResolveSetResetTime(in SeStringContext context, in ReadOnlySePayloadSpan payload)
|
private unsafe bool TryResolveSetResetTime(in SeStringContext context, in ReadOnlySePayloadSpan payload)
|
||||||
|
|
|
||||||
|
|
@ -101,16 +101,11 @@ public abstract class StyleModel
|
||||||
/// <exception cref="ArgumentOutOfRangeException">Thrown when the version of the style model is unknown.</exception>
|
/// <exception cref="ArgumentOutOfRangeException">Thrown when the version of the style model is unknown.</exception>
|
||||||
public string Serialize()
|
public string Serialize()
|
||||||
{
|
{
|
||||||
string prefix;
|
var prefix = this switch
|
||||||
switch (this)
|
|
||||||
{
|
{
|
||||||
case StyleModelV1:
|
StyleModelV1 => StyleModelV1.SerializedPrefix,
|
||||||
prefix = StyleModelV1.SerializedPrefix;
|
_ => throw new ArgumentOutOfRangeException(),
|
||||||
break;
|
};
|
||||||
default:
|
|
||||||
throw new ArgumentOutOfRangeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
return prefix + Convert.ToBase64String(Util.CompressString(JsonConvert.SerializeObject(this)));
|
return prefix + Convert.ToBase64String(Util.CompressString(JsonConvert.SerializeObject(this)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
using Dalamud.Utility;
|
using Dalamud.Utility;
|
||||||
|
|
@ -47,15 +47,11 @@ public abstract class ProfileModel
|
||||||
/// <exception cref="ArgumentOutOfRangeException">Thrown when an unsupported model is serialized.</exception>
|
/// <exception cref="ArgumentOutOfRangeException">Thrown when an unsupported model is serialized.</exception>
|
||||||
public string SerializeForShare()
|
public string SerializeForShare()
|
||||||
{
|
{
|
||||||
string prefix;
|
var prefix = this switch
|
||||||
switch (this)
|
|
||||||
{
|
{
|
||||||
case ProfileModelV1:
|
ProfileModelV1 => ProfileModelV1.SerializedPrefix,
|
||||||
prefix = ProfileModelV1.SerializedPrefix;
|
_ => throw new ArgumentOutOfRangeException(),
|
||||||
break;
|
};
|
||||||
default:
|
|
||||||
throw new ArgumentOutOfRangeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
// HACK: Just filter the ID for now, we should split the sharing + saving model
|
// HACK: Just filter the ID for now, we should split the sharing + saving model
|
||||||
var serialized = JsonConvert.SerializeObject(this, new JsonSerializerSettings()
|
var serialized = JsonConvert.SerializeObject(this, new JsonSerializerSettings()
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#define BORDER_MATCHING
|
#define BORDER_MATCHING
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
@ -32,18 +32,12 @@ internal readonly ref struct FuzzyMatcher
|
||||||
this.needleFinalPosition = this.needleSpan.Length - 1;
|
this.needleFinalPosition = this.needleSpan.Length - 1;
|
||||||
this.mode = matchMode;
|
this.mode = matchMode;
|
||||||
|
|
||||||
switch (matchMode)
|
this.needleSegments = matchMode switch
|
||||||
{
|
{
|
||||||
case MatchMode.FuzzyParts:
|
MatchMode.FuzzyParts => FindNeedleSegments(this.needleSpan),
|
||||||
this.needleSegments = FindNeedleSegments(this.needleSpan);
|
MatchMode.Fuzzy or MatchMode.Simple => EmptySegArray,
|
||||||
break;
|
_ => throw new ArgumentOutOfRangeException(nameof(matchMode), matchMode, null),
|
||||||
case MatchMode.Fuzzy:
|
};
|
||||||
case MatchMode.Simple:
|
|
||||||
this.needleSegments = EmptySegArray;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new ArgumentOutOfRangeException(nameof(matchMode), matchMode, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static (int Start, int End)[] FindNeedleSegments(ReadOnlySpan<char> span)
|
private static (int Start, int End)[] FindNeedleSegments(ReadOnlySpan<char> span)
|
||||||
|
|
|
||||||
|
|
@ -51,38 +51,22 @@ internal static unsafe partial class TerraFxComInterfaceExtensions
|
||||||
throw new ArgumentOutOfRangeException(nameof(mode), mode, null);
|
throw new ArgumentOutOfRangeException(nameof(mode), mode, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (access)
|
grfMode |= access switch
|
||||||
{
|
{
|
||||||
case FileAccess.Read:
|
FileAccess.Read => STGM.STGM_READ,
|
||||||
grfMode |= STGM.STGM_READ;
|
FileAccess.Write => STGM.STGM_WRITE,
|
||||||
break;
|
FileAccess.ReadWrite => (uint)STGM.STGM_READWRITE,
|
||||||
case FileAccess.Write:
|
_ => throw new ArgumentOutOfRangeException(nameof(access), access, null),
|
||||||
grfMode |= STGM.STGM_WRITE;
|
};
|
||||||
break;
|
|
||||||
case FileAccess.ReadWrite:
|
|
||||||
grfMode |= STGM.STGM_READWRITE;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new ArgumentOutOfRangeException(nameof(access), access, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (share)
|
grfMode |= share switch
|
||||||
{
|
{
|
||||||
case FileShare.None:
|
FileShare.None => STGM.STGM_SHARE_EXCLUSIVE,
|
||||||
grfMode |= STGM.STGM_SHARE_EXCLUSIVE;
|
FileShare.Read => STGM.STGM_SHARE_DENY_WRITE,
|
||||||
break;
|
FileShare.Write => STGM.STGM_SHARE_DENY_READ,
|
||||||
case FileShare.Read:
|
FileShare.ReadWrite => (uint)STGM.STGM_SHARE_DENY_NONE,
|
||||||
grfMode |= STGM.STGM_SHARE_DENY_WRITE;
|
_ => throw new NotSupportedException($"Only ${FileShare.Read} and ${FileShare.Write} are supported."),
|
||||||
break;
|
};
|
||||||
case FileShare.Write:
|
|
||||||
grfMode |= STGM.STGM_SHARE_DENY_READ;
|
|
||||||
break;
|
|
||||||
case FileShare.ReadWrite:
|
|
||||||
grfMode |= STGM.STGM_SHARE_DENY_NONE;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new NotSupportedException($"Only ${FileShare.Read} and ${FileShare.Write} are supported.");
|
|
||||||
}
|
|
||||||
|
|
||||||
using var stream = default(ComPtr<IStream>);
|
using var stream = default(ComPtr<IStream>);
|
||||||
fixed (char* pPath = path)
|
fixed (char* pPath = path)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue