OpenTween.Twitter.GetTextLengthRemainInternal C# (CSharp) Method

GetTextLengthRemainInternal() private method

private GetTextLengthRemainInternal ( string postText, bool isDm ) : int
postText string
isDm bool
return int
        private int GetTextLengthRemainInternal(string postText, bool isDm)
        {
            var textLength = 0;

            var pos = 0;
            while (pos < postText.Length)
            {
                textLength++;

                if (char.IsSurrogatePair(postText, pos))
                    pos += 2; // サロゲートペアの場合は2文字分進める
                else
                    pos++;
            }

            var urls = TweetExtractor.ExtractUrls(postText);
            foreach (var url in urls)
            {
                var shortUrlLength = url.StartsWith("https://", StringComparison.OrdinalIgnoreCase)
                    ? this.Configuration.ShortUrlLengthHttps
                    : this.Configuration.ShortUrlLength;

                textLength += shortUrlLength - url.Length;
            }

            if (isDm)
                return this.Configuration.DmTextCharacterLimit - textLength;
            else
                return 140 - textLength;
        }