22size_t FindWebLinkEnding(
const WideString& str, size_t start, size_t end) {
117 bool bAfterHyphen =
false;
118 bool bLineBreak =
false;
119 const size_t nTotalChar = m_pTextPage->CountChars();
120 const WideString page_text = m_pTextPage->GetAllPageText();
121 while (pos < nTotalChar) {
124 char_info
.m_Unicode != L' ' && pos != nTotalChar - 1) {
133 size_t nCount = pos - start;
134 if (pos == nTotalChar - 1) {
136 }
else if (bAfterHyphen &&
144 WideString strBeCheck = page_text.Substr(start, nCount);
146 strBeCheck.Remove(L'\n');
147 strBeCheck.Remove(L'\r');
151 strBeCheck.Replace(L"\xfffe", L"-");
153 if (strBeCheck.GetLength() > 5) {
154 while (strBeCheck.GetLength() > 0) {
155 wchar_t ch = strBeCheck
.Back();
156 if (ch != L')' && ch != L',' && ch != L'>' && ch != L'.')
159 strBeCheck = strBeCheck.First(strBeCheck.GetLength() - 1);
166 auto maybe_link = CheckWebLink(strBeCheck);
167 if (maybe_link.has_value()) {
168 maybe_link.value().m_Start += start;
169 m_LinkArray.push_back(maybe_link.value());
171 m_LinkArray.push_back(Link{{start, nCount}, strBeCheck});
180 const WideString& strBeCheck) {
181 static const wchar_t kHttpScheme[] = L"http";
182 static const wchar_t kWWWAddrStart[] = L"www.";
184 const size_t kHttpSchemeLen = FXSYS_len(kHttpScheme);
185 const size_t kWWWAddrStartLen = FXSYS_len(kWWWAddrStart);
187 WideString str = strBeCheck;
191 auto start = str.Find(kHttpScheme);
192 if (start.has_value()) {
193 size_t off = start.value() + kHttpSchemeLen;
194 if (str.GetLength() > off + 4) {
195 if (str[off] == L's')
197 if (str[off] == L':' && str[off + 1] == L'/' && str[off + 2] == L'/') {
200 FindWebLinkEnding(str, off,
201 TrimExternalBracketsFromWebLink(
202 str, start.value(), str.GetLength() - 1));
204 const size_t nStart = start.value();
205 const size_t nCount = end - nStart + 1;
206 return Link{{nStart, nCount}, strBeCheck.Substr(nStart, nCount)};
213 start = str.Find(kWWWAddrStart);
214 if (start.has_value()) {
215 size_t off = start.value() + kWWWAddrStartLen;
216 if (str.GetLength() > off) {
218 FindWebLinkEnding(str, start.value(),
219 TrimExternalBracketsFromWebLink(
220 str, start.value(), str.GetLength() - 1));
222 const size_t nStart = start.value();
223 const size_t nCount = end - nStart + 1;
224 return Link{{nStart, nCount},
225 L"http://" + strBeCheck.Substr(nStart, nCount)};
230 return absl::nullopt;
234 auto aPos = str->Find(L'@');
236 if (!aPos.has_value() || aPos.value() == 0 || aPos == str->GetLength() - 1)
240 size_t pPos = aPos.value();
241 for (size_t i = aPos.value(); i > 0; i--) {
242 wchar_t ch = (*str)[i - 1];
246 if (ch != L'.' || i == pPos || i == 1) {
247 if (i == aPos.value()) {
253 size_t removed_len = i == pPos ? i + 1 : i;
254 *str = str->Last(str->GetLength() - removed_len);
262 aPos = str->Find(L'@');
263 if (!aPos.has_value() || aPos.value() == 0)
270 auto ePos = str->Find(L'.', aPos.value() + 1);
271 if (!ePos.has_value() || ePos.value() == aPos.value() + 1)
275 size_t nLen = str->GetLength();
277 for (size_t i = aPos.value() + 1; i < nLen; i++) {
278 wchar_t wch = (*str)[i];
282 if (wch != L'.' || i == pPos + 1) {
284 size_t host_end = i == pPos + 1 ? i - 2 : i - 1;
285 if (pPos > 0 && host_end - aPos.value() >= 3) {
287 *str = str->First(host_end + 1);
295 if (!str->Contains(L"mailto:"))
296 *str
= L"mailto:"
+ *str;