Skip to content

Commit e00b6e6

Browse files
committed
Replace char count
1 parent 8e566a0 commit e00b6e6

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

Assets/Hypertext/Examples/RegexHypertext.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Text.RegularExpressions;
45
using UnityEngine;
56

@@ -62,7 +63,7 @@ public override void RemoveListeners()
6263
/// </summary>
6364
protected override void AddListeners()
6465
{
65-
var lineCount = CountChar(text, '\n') + 1;
66+
var lineCount = text.Count(x => x == '\n') + 1;
6667
bool hasFolded = lineCount != cachedTextGenerator.lineCount;
6768

6869
foreach (var entry in entries)
@@ -78,7 +79,7 @@ protected override void AddListeners()
7879
{
7980
// 折り返していない場合のみ「空白」と「改行」が描画されないため、調整する
8081
var head = text.Substring(0, match.Index);
81-
var count = CountChar(head, ' ') + CountChar(head, '\n');
82+
var count = head.Count(x => x == ' ') + head.Count(x => x == '\n');
8283
OnClick(match.Index - count, match.Value.Length, entry.Color, entry.Callback);
8384
}
8485
#else
@@ -87,11 +88,5 @@ protected override void AddListeners()
8788
}
8889
}
8990
}
90-
91-
// 文字の出現回数をカウント
92-
public static int CountChar(string s, char c)
93-
{
94-
return s.Length - s.Replace(c.ToString(), "").Length;
95-
}
9691
}
9792
}

0 commit comments

Comments
 (0)