ExpandedSearchInfo/ExpandedSearchInfo/Util.cs

32 lines
998 B
C#
Raw Normal View History

2021-02-18 20:20:40 +00:00
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
2021-04-11 12:27:32 +00:00
using Dalamud.Game.Text.SeStringHandling;
2021-02-18 20:20:40 +00:00
using ImGuiNET;
2023-09-29 01:09:50 +00:00
namespace ExpandedSearchInfo;
2021-02-18 20:20:40 +00:00
2023-09-29 01:09:50 +00:00
internal static class Util {
private static readonly Regex BbCodeTag = new(@"\[/?\w+(?:=.+?)?\]", RegexOptions.Compiled | RegexOptions.IgnoreCase);
2021-02-18 20:20:40 +00:00
2023-09-29 01:09:50 +00:00
internal static unsafe SeString ReadRawSeString(IntPtr data) {
var bytes = new List<byte>();
2021-02-18 20:20:40 +00:00
2023-09-29 01:09:50 +00:00
var ptr = (byte*) data;
while (*ptr != 0) {
bytes.Add(*ptr);
ptr += 1;
2021-02-18 20:20:40 +00:00
}
2023-09-29 01:09:50 +00:00
return SeString.Parse(bytes.ToArray());
}
internal static string StripBbCode(this string input) => BbCodeTag.Replace(input, "");
2021-02-18 20:20:40 +00:00
2023-09-29 01:09:50 +00:00
internal static void DrawLines(string input) {
// FIXME: this is a workaround for imgui breaking on extremely long strings
foreach (var line in input.Split(new[] {"\n", "\r", "\r\n"}, StringSplitOptions.None)) {
ImGui.TextUnformatted(line);
2021-02-18 20:20:40 +00:00
}
}
2023-09-29 01:09:50 +00:00
}