This commit is contained in:
龙腾猫跃 committed 2026-04-28 01:13:03 +08:00
1 parent 53ed257072
commit 2b3e6e211a
3 files changed
+16 -11

No files matched your search

+1 -1
View File
@@ -166,7 +166,7 @@ public static class StringExtensions {
/// <summary> /// <summary>
/// 将字符串中的换行符统一替换为指定字符。 /// 将字符串中的换行符统一替换为指定字符。
/// 若指定了 <paramref name="mergeMultiple"/>,会将多次换行合并成一次换行。 /// 若指定了 <paramref name="mergeMultiple"/>,会将多个连续换行符仅替换为一个目标内容。
/// </summary> /// </summary>
public static string ReplaceLineEndings(this string input, string newValue, bool mergeMultiple = false) => public static string ReplaceLineEndings(this string input, string newValue, bool mergeMultiple = false) =>
Regex.Replace(input, Regex.Replace(input,
+5
View File
@@ -1,4 +1,9 @@
namespace MeloongCore; namespace MeloongCore;
/// <summary>
/// 线程安全的 <see cref="List{T}"/> 实现。
/// 在 <see cref="SynchronizedCollection{T}"/> 的基础上,当调用枚举器时返回一个临时副本,以避免列表在枚举过程中被修改导致异常。
/// </summary>
public class ConcurrentList<T> : SynchronizedCollection<T>, IEnumerable, IEnumerable<T> { public class ConcurrentList<T> : SynchronizedCollection<T>, IEnumerable, IEnumerable<T> {
// 构造函数 // 构造函数
+10 -10
View File
@@ -8,9 +8,9 @@ public static class MathUtils {
/// <summary> /// <summary>
/// 将字符串作为数字,转换为指定进制的形式。 /// 将字符串作为数字,转换为指定进制的形式。
/// 进制数需在 2 到 86 之间,且输入字符串中的每个字符都必须在该进制的字符集中。 /// 进制数需在 2 到 86 之间,且输入字符串中的每个字符都必须在该进制的字符集中。
/// 进制参考:含大写字母 36,含大小写字母 62,含大小写字母和特殊符号 86 /// 进制参考:含大写字母 36,含大小写字母 62,含大小写字母和特殊符号 86。
/// </summary> /// </summary>
public static string RadixConvert(this string input, int fromRadix, int toRadix) { public static string ConvertRadix(this string input, int fromRadix, int toRadix) {
const string digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/+=!?@#$%^&*()[]{}<>;:',"; const string digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/+=!?@#$%^&*()[]{}<>;:',";
if (fromRadix < 2 || fromRadix > digits.Length) throw new ArgumentOutOfRangeException(nameof(fromRadix), $"{nameof(fromRadix)} must be between 2 and 86."); if (fromRadix < 2 || fromRadix > digits.Length) throw new ArgumentOutOfRangeException(nameof(fromRadix), $"{nameof(fromRadix)} must be between 2 and 86.");
// 零与负数的预处理 // 零与负数的预处理
@@ -24,24 +24,24 @@ public static class MathUtils {
if (digit == -1 || digit >= fromRadix) throw new ArgumentException($"Character '{c}' in input '{input}' is not a valid digit for radix {fromRadix}."); if (digit == -1 || digit >= fromRadix) throw new ArgumentException($"Character '{c}' in input '{input}' is not a valid digit for radix {fromRadix}.");
realNum = realNum * fromRadix + digit; realNum = realNum * fromRadix + digit;
} }
return RadixConvert(realNum * (isNegative ? -1 : 1), toRadix); return ConvertRadix(realNum * (isNegative ? -1 : 1), toRadix);
} }
/// <summary> /// <summary>
/// 转换为 2 到 86 进制的字符串。 /// 转换为 2 到 86 进制的字符串。
/// 进制参考:含大写字母 36,含大小写字母 62,含大小写字母和特殊符号 86 /// 进制参考:含大写字母 36,含大小写字母 62,含大小写字母和特殊符号 86。
/// </summary> /// </summary>
public static string RadixConvert(this long input, int toRadix) => RadixConvert((BigInteger) input, toRadix); public static string ConvertRadix(this long input, int toRadix) => ConvertRadix((BigInteger) input, toRadix);
/// <summary> /// <summary>
/// 转换为 2 到 86 进制的字符串。 /// 转换为 2 到 86 进制的字符串。
/// 进制参考:含大写字母 36,含大小写字母 62,含大小写字母和特殊符号 86 /// 进制参考:含大写字母 36,含大小写字母 62,含大小写字母和特殊符号 86。
/// </summary> /// </summary>
public static string RadixConvert(this int input, int toRadix) => RadixConvert((BigInteger) input, toRadix); public static string ConvertRadix(this int input, int toRadix) => ConvertRadix((BigInteger) input, toRadix);
/// <summary> /// <summary>
/// 转换为 2 到 86 进制的字符串。 /// 转换为 2 到 86 进制的字符串。
/// 进制参考:含大写字母 36,含大小写字母 62,含大小写字母和特殊符号 86 /// 进制参考:含大写字母 36,含大小写字母 62,含大小写字母和特殊符号 86。
/// </summary> /// </summary>
public static string RadixConvert(this byte input, int toRadix) => RadixConvert((BigInteger) input, toRadix); public static string ConvertRadix(this byte input, int toRadix) => ConvertRadix((BigInteger) input, toRadix);
private static string RadixConvert(this BigInteger input, int toRadix) { private static string ConvertRadix(this BigInteger input, int toRadix) {
const string digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/+=!?@#$%^&*()[]{}<>;:',"; const string digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/+=!?@#$%^&*()[]{}<>;:',";
if (toRadix < 2 || toRadix > digits.Length) throw new ArgumentOutOfRangeException(nameof(toRadix), $"{nameof(toRadix)} must be between 2 and 86."); if (toRadix < 2 || toRadix > digits.Length) throw new ArgumentOutOfRangeException(nameof(toRadix), $"{nameof(toRadix)} must be between 2 and 86.");
// 零与负数的预处理 // 零与负数的预处理