1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
|
/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Hyperlinks.h"
#include "Common.h"
#include "DB2Stores.h"
#include "Errors.h"
#include "ItemTemplate.h"
#include "ObjectMgr.h"
#include "QuestDef.h"
#include "SharedDefines.h"
#include "SpellInfo.h"
#include "SpellMgr.h"
#include "StringFormat.h"
#include "World.h"
using namespace Trinity::Hyperlinks;
inline uint8 toHex(char c) { return (c >= '0' && c <= '9') ? c - '0' + 0x10 : (c >= 'a' && c <= 'f') ? c - 'a' + 0x1a : 0x00; }
// Validates a single hyperlink
HyperlinkInfo Trinity::Hyperlinks::ParseSingleHyperlink(std::string_view str)
{
uint32 color = 0;
std::string_view tag;
std::string_view data;
std::string_view text;
//color tag
if (str.substr(0, 2) != "|c")
return {};
str.remove_prefix(2);
if (str.length() < 8)
return {};
for (uint8 i = 0; i < 8; ++i)
{
if (uint8 hex = toHex(str[i]))
color = (color << 4) | (hex & 0xf);
else
return {};
}
str.remove_prefix(8);
if (str.substr(0, 2) != "|H")
return {};
str.remove_prefix(2);
// tag+data part follows
if (size_t delimPos = str.find('|'); delimPos != std::string_view::npos)
{
tag = str.substr(0, delimPos);
str.remove_prefix(delimPos+1);
}
else
return {};
// split tag if : is present (data separator)
if (size_t dataStart = tag.find(':'); dataStart != std::string_view::npos)
{
data = tag.substr(dataStart+1);
tag = tag.substr(0, dataStart);
}
// ok, next should be link data end tag...
if (str.substr(0, 1) != "h")
return {};
str.remove_prefix(1);
// skip to final |
if (size_t end = str.find('|'); end != std::string_view::npos)
{
// check end tag
if (str.substr(end, 4) != "|h|r")
return {};
// check text brackets
if ((str[0] != '[') || (str[end - 1] != ']'))
return {};
text = str.substr(1, end - 2);
// tail
str = str.substr(end + 4);
}
else
return {};
// ok, valid hyperlink, return info
return { str, color, tag, data, text };
}
template <typename T>
struct LinkValidator
{
static bool IsTextValid(typename T::value_type, std::string_view) { return true; }
static bool IsColorValid(typename T::value_type, HyperlinkColor) { return true; }
};
static bool IsCreatureNameValid(uint32 creatureId, std::string_view text)
{
if (CreatureTemplate const* creatureTemplate = sObjectMgr->GetCreatureTemplate(creatureId))
{
CreatureLocale const* locale = sObjectMgr->GetCreatureLocale(creatureId);
if (!locale)
return creatureTemplate->Name == text;
for (uint8 i = 0; i < TOTAL_LOCALES; ++i)
{
std::string const& name = (i == DEFAULT_LOCALE) ? creatureTemplate->Name : locale->Name[i];
if (name.empty())
continue;
if (name == text)
return true;
}
}
return false;
}
template <>
struct LinkValidator<LinkTags::spell>
{
static bool IsTextValid(SpellLinkData const& data, std::string_view text)
{
return IsTextValid(data.Spell, text);
}
static bool IsTextValid(SpellInfo const* info, std::string_view text)
{
for (LocaleConstant i = LOCALE_enUS; i < TOTAL_LOCALES; i = LocaleConstant(i + 1))
if ((*info->SpellName)[i] == text)
return true;
return false;
}
static bool IsColorValid(SpellLinkData const&, HyperlinkColor c)
{
return c == CHAT_LINK_COLOR_SPELL;
}
};
template <>
struct LinkValidator<LinkTags::achievement>
{
static bool IsTextValid(AchievementLinkData const& data, std::string_view text)
{
if (text.empty())
return false;
for (LocaleConstant i = LOCALE_enUS; i < TOTAL_LOCALES; i = LocaleConstant(i + 1))
if (text == data.Achievement->Title[i])
return true;
return false;
}
static bool IsColorValid(AchievementLinkData const&, HyperlinkColor c)
{
return c == CHAT_LINK_COLOR_ACHIEVEMENT;
}
};
template <>
struct LinkValidator<LinkTags::apower>
{
static bool IsTextValid(ArtifactPowerLinkData const& data, std::string_view text)
{
if (SpellInfo const* info = sSpellMgr->GetSpellInfo(data.ArtifactPower->SpellID, DIFFICULTY_NONE))
return LinkValidator<LinkTags::spell>::IsTextValid(info, text);
return false;
}
static bool IsColorValid(ArtifactPowerLinkData const&, HyperlinkColor c)
{
return c == CHAT_LINK_COLOR_ARTIFACT_POWER;
}
};
template <>
struct LinkValidator<LinkTags::azessence>
{
static bool IsTextValid(AzeriteEssenceLinkData const& data, std::string_view text)
{
for (LocaleConstant i = LOCALE_enUS; i < TOTAL_LOCALES; i = LocaleConstant(i + 1))
if (data.Essence->Name[i] == text)
return true;
return false;
}
static bool IsColorValid(AzeriteEssenceLinkData const& data, HyperlinkColor c)
{
return c == ItemQualityColors[data.Rank + 1];
}
};
template <>
struct LinkValidator<LinkTags::battlepet>
{
static bool IsTextValid(BattlePetLinkData const& data, std::string_view text)
{
return IsCreatureNameValid(data.Species->CreatureID, text);
}
static bool IsColorValid(BattlePetLinkData const& data, HyperlinkColor c)
{
return c == ItemQualityColors[data.Quality];
}
};
template <>
struct LinkValidator<LinkTags::conduit>
{
static bool IsTextValid(SoulbindConduitRankEntry const* rank, std::string_view text)
{
if (SpellInfo const* info = sSpellMgr->GetSpellInfo(rank->SpellID, DIFFICULTY_NONE))
return LinkValidator<LinkTags::spell>::IsTextValid(info, text);
return false;
}
static bool IsColorValid(SoulbindConduitRankEntry const*, HyperlinkColor c)
{
return c == CHAT_LINK_COLOR_SPELL;
}
};
template <>
struct LinkValidator<LinkTags::currency>
{
static bool IsTextValid(CurrencyLinkData const& data, std::string_view text)
{
LocalizedString const* name = data.Container ? &data.Container->ContainerName : &data.Currency->Name;
for (LocaleConstant i = LOCALE_enUS; i < TOTAL_LOCALES; i = LocaleConstant(i + 1))
if ((*name)[i] == text)
return true;
return false;
}
static bool IsColorValid(CurrencyLinkData const& data, HyperlinkColor c)
{
return c == ItemQualityColors[(data.Container ? data.Container->ContainerQuality : data.Currency->Quality)];
}
};
template <>
struct LinkValidator<LinkTags::enchant>
{
static bool IsTextValid(SpellInfo const* info, std::string_view text)
{
if (LinkValidator<LinkTags::spell>::IsTextValid(info, text))
return true;
SkillLineAbilityMapBounds bounds = sSpellMgr->GetSkillLineAbilityMapBounds(info->Id);
if (bounds.first == bounds.second)
return false;
for (auto pair = bounds.first; pair != bounds.second; ++pair)
{
SkillLineEntry const* skill = sSkillLineStore.LookupEntry(pair->second->SkillupSkillLineID
? pair->second->SkillupSkillLineID
: pair->second->SkillLine);
if (!skill)
return false;
for (LocaleConstant i = LOCALE_enUS; i < TOTAL_LOCALES; i = LocaleConstant(i + 1))
{
std::string_view skillName = skill->DisplayName[i];
std::string_view spellName = (*info->SpellName)[i];
if ((text.length() == (skillName.length() + 2 + spellName.length())) &&
(text.substr(0, skillName.length()) == skillName) &&
(text.substr(skillName.length(), 2) == ": ") &&
(text.substr(skillName.length() + 2) == spellName))
return true;
}
}
return false;
}
static bool IsColorValid(SpellInfo const*, HyperlinkColor c)
{
return c == CHAT_LINK_COLOR_ENCHANT;
}
};
template <>
struct LinkValidator<LinkTags::garrfollower>
{
static bool IsTextValid(GarrisonFollowerLinkData const& data, std::string_view text)
{
return IsCreatureNameValid(data.Follower->HordeCreatureID, text)
|| IsCreatureNameValid(data.Follower->AllianceCreatureID, text);
}
static bool IsColorValid(GarrisonFollowerLinkData const& data, HyperlinkColor c)
{
return c == ItemQualityColors[data.Quality];
}
};
template <>
struct LinkValidator<LinkTags::garrfollowerability>
{
static bool IsTextValid(GarrAbilityEntry const* ability, std::string_view text)
{
for (LocaleConstant i = LOCALE_enUS; i < TOTAL_LOCALES; i = LocaleConstant(i + 1))
if (ability->Name[i] == text)
return true;
return false;
}
static bool IsColorValid(GarrAbilityEntry const*, HyperlinkColor c)
{
return c == CHAT_LINK_COLOR_GARR_ABILITY;
}
};
template <>
struct LinkValidator<LinkTags::garrmission>
{
static bool IsTextValid(GarrisonMissionLinkData const& data, std::string_view text)
{
for (LocaleConstant i = LOCALE_enUS; i < TOTAL_LOCALES; i = LocaleConstant(i + 1))
if (data.Mission->Name[i] == text)
return true;
return false;
}
static bool IsColorValid(GarrisonMissionLinkData const&, HyperlinkColor c)
{
return c == QuestDifficultyColors[2];
}
};
template <>
struct LinkValidator<LinkTags::instancelock>
{
static bool IsTextValid(InstanceLockLinkData const& data, std::string_view text)
{
for (LocaleConstant i = LOCALE_enUS; i < TOTAL_LOCALES; i = LocaleConstant(i + 1))
if (data.Map->MapName[i] == text)
return true;
return false;
}
static bool IsColorValid(InstanceLockLinkData const&, HyperlinkColor c)
{
return c == CHAT_LINK_COLOR_INSTANCE_LOCK;
}
};
template <>
struct LinkValidator<LinkTags::item>
{
static bool IsTextValid(ItemLinkData const& data, std::string_view text)
{
LocalizedString const* suffixStrings = nullptr;
if (!data.Item->HasFlag(ITEM_FLAG3_HIDE_NAME_SUFFIX) && data.Suffix)
suffixStrings = &data.Suffix->Description;
return IsTextValid(data.Item, suffixStrings, text);
}
static bool IsTextValid(ItemTemplate const* itemTemplate, LocalizedString const* suffixStrings, std::string_view text)
{
for (LocaleConstant i = LOCALE_enUS; i < TOTAL_LOCALES; i = LocaleConstant(i + 1))
{
std::string_view name = itemTemplate->GetName(i);
if (name.empty())
continue;
if (suffixStrings)
{
std::string_view suffix = (*suffixStrings)[i];
if (
(!suffix.empty()) &&
(text.length() == (name.length() + 1 + suffix.length())) &&
(text.substr(0, name.length()) == name) &&
(text[name.length()] == ' ') &&
(text.substr(name.length() + 1) == suffix)
)
return true;
}
else if (text == name)
return true;
}
return false;
}
static bool IsColorValid(ItemLinkData const& data, HyperlinkColor c)
{
return c == ItemQualityColors[data.Quality];
}
};
template <>
struct LinkValidator<LinkTags::journal>
{
static bool IsTextValid(JournalLinkData const& data, std::string_view text)
{
for (LocaleConstant i = LOCALE_enUS; i < TOTAL_LOCALES; i = LocaleConstant(i + 1))
if ((*data.ExpectedText)[i] == text)
return true;
return false;
}
static bool IsColorValid(JournalLinkData const&, HyperlinkColor c)
{
return c == CHAT_LINK_COLOR_JOURNAL;
}
};
template <>
struct LinkValidator<LinkTags::keystone>
{
static bool IsTextValid(KeystoneLinkData const& data, std::string_view text)
{
// Skip "Keystone" prefix - not loading GlobalStrings.db2
size_t validateStartPos = text.find(": ");
if (validateStartPos == std::string_view::npos)
return false;
text.remove_prefix(validateStartPos);
text.remove_prefix(2); // skip ": " too
for (LocaleConstant i = LOCALE_enUS; i < TOTAL_LOCALES; i = LocaleConstant(i + 1))
{
std::string expectedText = Trinity::StringFormat("%s (%u)", data.Map->Name[i], data.Level);
if (expectedText == text)
return true;
}
return false;
}
static bool IsColorValid(KeystoneLinkData const&, HyperlinkColor c)
{
return c == ItemQualityColors[ITEM_QUALITY_EPIC];
}
};
template <>
struct LinkValidator<LinkTags::quest>
{
static bool IsTextValid(QuestLinkData const& data, std::string_view text)
{
if (text.empty())
return false;
if (text == data.Quest->GetLogTitle())
return true;
QuestTemplateLocale const* locale = sObjectMgr->GetQuestLocale(data.Quest->GetQuestId());
if (!locale)
return false;
for (uint8 i = 0; i < TOTAL_LOCALES; ++i)
{
if (i == DEFAULT_LOCALE)
continue;
std::string_view name = ObjectMgr::GetLocaleString(locale->LogTitle, LocaleConstant(i));
if (!name.empty() && (text == name))
return true;
}
return false;
}
static bool IsColorValid(QuestLinkData const&, HyperlinkColor c)
{
for (uint8 i = 0; i < MAX_QUEST_DIFFICULTY; ++i)
if (c == QuestDifficultyColors[i])
return true;
return false;
}
};
template <>
struct LinkValidator<LinkTags::mawpower>
{
static bool IsTextValid(MawPowerEntry const* mawPower, std::string_view text)
{
if (SpellInfo const* info = sSpellMgr->GetSpellInfo(mawPower->SpellID, DIFFICULTY_NONE))
return LinkValidator<LinkTags::spell>::IsTextValid(info, text);
return false;
}
static bool IsColorValid(MawPowerEntry const*, HyperlinkColor c)
{
return c == CHAT_LINK_COLOR_SPELL;
}
};
template <>
struct LinkValidator<LinkTags::outfit>
{
static bool IsTextValid(std::string const&, std::string_view)
{
return true;
}
static bool IsColorValid(std::string const&, HyperlinkColor c)
{
return c == CHAT_LINK_COLOR_TRANSMOG;
}
};
template <>
struct LinkValidator<LinkTags::pvptal>
{
static bool IsTextValid(PvpTalentEntry const* pvpTalent, std::string_view text)
{
if (SpellInfo const* info = sSpellMgr->GetSpellInfo(pvpTalent->SpellID, DIFFICULTY_NONE))
return LinkValidator<LinkTags::spell>::IsTextValid(info, text);
return false;
}
static bool IsColorValid(PvpTalentEntry const*, HyperlinkColor c)
{
return c == CHAT_LINK_COLOR_TALENT;
}
};
template <>
struct LinkValidator<LinkTags::talent>
{
static bool IsTextValid(TalentEntry const* talent, std::string_view text)
{
if (SpellInfo const* info = sSpellMgr->GetSpellInfo(talent->SpellID, DIFFICULTY_NONE))
return LinkValidator<LinkTags::spell>::IsTextValid(info, text);
return false;
}
static bool IsColorValid(TalentEntry const*, HyperlinkColor c)
{
return c == CHAT_LINK_COLOR_TALENT;
}
};
template <>
struct LinkValidator<LinkTags::trade>
{
static bool IsTextValid(TradeskillLinkData const& data, std::string_view text)
{
return LinkValidator<LinkTags::spell>::IsTextValid(data.Spell, text);
}
static bool IsColorValid(TradeskillLinkData const&, HyperlinkColor c)
{
return c == CHAT_LINK_COLOR_TRADE;
}
};
template <>
struct LinkValidator<LinkTags::transmogappearance>
{
static bool IsTextValid(ItemModifiedAppearanceEntry const* enchantment, std::string_view text)
{
if (ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(enchantment->ItemID))
return LinkValidator<LinkTags::item>::IsTextValid(itemTemplate, nullptr, text);
return false;
}
static bool IsColorValid(ItemModifiedAppearanceEntry const*, HyperlinkColor c)
{
return c == CHAT_LINK_COLOR_TRANSMOG;
}
};
template <>
struct LinkValidator<LinkTags::transmogillusion>
{
static bool IsTextValid(SpellItemEnchantmentEntry const* enchantment, std::string_view text)
{
for (LocaleConstant i = LOCALE_enUS; i < TOTAL_LOCALES; i = LocaleConstant(i + 1))
if (enchantment->Name[i] == text)
return true;
for (LocaleConstant i = LOCALE_enUS; i < TOTAL_LOCALES; i = LocaleConstant(i + 1))
if (enchantment->HordeName[i] == text)
return true;
return false;
}
static bool IsColorValid(SpellItemEnchantmentEntry const*, HyperlinkColor c)
{
return c == CHAT_LINK_COLOR_TRANSMOG;
}
};
template <>
struct LinkValidator<LinkTags::transmogset>
{
static bool IsTextValid(TransmogSetEntry const* set, std::string_view text)
{
for (LocaleConstant i = LOCALE_enUS; i < TOTAL_LOCALES; i = LocaleConstant(i + 1))
{
if (ItemNameDescriptionEntry const* itemNameDescription = sItemNameDescriptionStore.LookupEntry(set->ItemNameDescriptionID))
{
std::string expectedText = Trinity::StringFormat("%s (%s)", set->Name[i], itemNameDescription->Description[i]);
if (expectedText.c_str() == text)
return true;
}
else if (set->Name[i] == text)
return true;
}
return false;
}
static bool IsColorValid(TransmogSetEntry const*, HyperlinkColor c)
{
return c == CHAT_LINK_COLOR_TRANSMOG;
}
};
template <>
struct LinkValidator<LinkTags::worldmap>
{
static bool IsTextValid(WorldMapLinkData const&, std::string_view)
{
return true;
}
static bool IsColorValid(WorldMapLinkData const&, HyperlinkColor c)
{
return c == CHAT_LINK_COLOR_ACHIEVEMENT;
}
};
template <typename TAG>
static bool ValidateAs(HyperlinkInfo const& info)
{
std::decay_t<typename TAG::value_type> t;
if (!TAG::StoreTo(t, info.data))
return false;
int32 const severity = static_cast<int32>(sWorld->getIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_SEVERITY));
if (severity >= 0)
{
if (!LinkValidator<TAG>::IsColorValid(t, info.color))
return false;
if (severity >= 1)
{
if (!LinkValidator<TAG>::IsTextValid(t, info.text))
return false;
}
}
return true;
}
#define TryValidateAs(T) do { if (info.tag == T::tag()) return ValidateAs<T>(info); } while (0)
static bool ValidateLinkInfo(HyperlinkInfo const& info)
{
using namespace LinkTags;
TryValidateAs(achievement);
TryValidateAs(apower);
TryValidateAs(azessence);
TryValidateAs(area);
TryValidateAs(areatrigger);
TryValidateAs(battlepet);
TryValidateAs(conduit);
TryValidateAs(creature);
TryValidateAs(creature_entry);
TryValidateAs(currency);
TryValidateAs(enchant);
TryValidateAs(gameevent);
TryValidateAs(gameobject);
TryValidateAs(gameobject_entry);
TryValidateAs(garrfollower);
TryValidateAs(garrfollowerability);
TryValidateAs(garrmission);
TryValidateAs(instancelock);
TryValidateAs(item);
TryValidateAs(itemset);
TryValidateAs(journal);
TryValidateAs(keystone);
TryValidateAs(mawpower);
TryValidateAs(outfit);
TryValidateAs(player);
TryValidateAs(pvptal);
TryValidateAs(quest);
TryValidateAs(skill);
TryValidateAs(spell);
TryValidateAs(talent);
TryValidateAs(taxinode);
TryValidateAs(tele);
TryValidateAs(title);
TryValidateAs(trade);
TryValidateAs(transmogappearance);
TryValidateAs(transmogillusion);
TryValidateAs(transmogset);
TryValidateAs(worldmap);
return false;
}
// Validates all hyperlinks and control sequences contained in str
bool Trinity::Hyperlinks::CheckAllLinks(std::string_view str)
{
// Step 1: Disallow all control sequences except ||, |H, |h, |c and |r
{
std::string_view::size_type pos = 0;
while ((pos = str.find('|', pos)) != std::string::npos)
{
++pos;
if (pos == str.length())
return false;
char next = str[pos];
if (next == 'H' || next == 'h' || next == 'c' || next == 'r' || next == '|')
++pos;
else
return false;
}
}
// Step 2: Parse all link sequences
// They look like this: |c<color>|H<linktag>:<linkdata>|h[<linktext>]|h|r
// - <color> is 8 hex characters AARRGGBB
// - <linktag> is arbitrary length [a-z_]
// - <linkdata> is arbitrary length, no | contained
// - <linktext> is printable
{
std::string::size_type pos;
while ((pos = str.find('|')) != std::string::npos)
{
if (str[pos + 1] == '|') // this is an escaped pipe character (||)
{
str = str.substr(pos + 2);
continue;
}
HyperlinkInfo info = ParseSingleHyperlink(str.substr(pos));
if (!info || !ValidateLinkInfo(info))
return false;
// tag is fine, find the next one
str = info.tail;
}
}
// all tags are valid
return true;
}
|