Twitch SDK (Internal)
chatmessageparsing.h
Go to the documentation of this file.
1 /********************************************************************************************
2 * Twitch Broadcasting SDK
3 *
4 * This software is supplied under the terms of a license agreement with Twitch Interactive, Inc. and
5 * may not be copied or used except in accordance with the terms of that agreement
6 * Copyright (c) 2012-2016 Twitch Interactive, Inc.
7 *********************************************************************************************/
8 
9 #pragma once
10 
13 #include <vector>
14 #include <regex>
15 
16 
17 namespace ttv
18 {
19  namespace chat
20  {
22  {
27  };
28 
30  {
32  };
33 
34  struct MentionRange
35  {
36  };
37 
38  struct UrlRange
39  {
40  };
41 
42  struct BitsRange
43  {
44  uint32_t prefixLength;
45  uint32_t numBits;
46  };
47 
48  struct TokenRange
49  {
52  int endIndex; // inclusive
53  int rangeNum; // To stable sort
54  union
55  {
56  EmoticonRange emoticon;
57  MentionRange mention;
58  UrlRange url;
59  BitsRange bits;
60  } data;
61  };
62 
64  bool SortTokenRangesByStartIndex(const TokenRange& a, const TokenRange& b);
65  bool SortEmoticonRangesByEmoticonId(const TokenRange& a, const TokenRange& b);
66 
67  void RemoveOverlappingRanges(std::vector<TokenRange>& ranges);
68  void AdjustByteRangesToUtf8Ranges(std::vector<TokenRange>& ranges, const std::string& message);
69  void AdjustUtf8RangesToByteRanges(std::vector<TokenRange>& ranges, const std::string& message);
70 
71  struct EmoteRange
72  {
74  int endIndex;
75  };
76 
80  bool ParseEmotesMessageTag(const std::string& emotesMessageTag, std::map<EmoticonId, std::vector<EmoteRange>>& result);
85  bool ParseBadgesMessageTag(const std::string& messageTag, std::vector<std::pair<std::string, std::string>>& result);
90  bool GenerateBadgesMessageTag(const std::vector<std::pair<std::string, std::string>>& badges, std::string& result);
91 
92  bool TokenizeLocalMessage(const std::shared_ptr<User>& user, ChannelId channelId, const std::string& message, std::string& emotesMessageTag, std::string& badgesMessageTag);
93 
94  void TokenizeServerMessage(const std::string& message, const TokenizationOptions& tokenizationOptions, const std::string& messageTags, const std::shared_ptr<BitsConfiguration>& bitsConfig, const std::vector<std::string>& localUserNames, MessageInfo& tokenizedMessage);
95 
96  void TokenizeServerMessage(const std::string& message, const TokenizationOptions& tokenizationOptions, const std::map<EmoticonId, std::vector<EmoteRange>>& emoticonRanges, const std::vector<std::string>& localUserNames, MessageInfo& tokenizedMessage);
97 
98  void TokenizeServerMessage(const std::string& message, const TokenizationOptions& tokenizationOptions, const std::map<EmoticonId, std::vector<EmoteRange>>& emoticonRanges, const std::shared_ptr<BitsConfiguration>& bitsConfig, const std::vector<std::string>& localUserNames, MessageInfo& tokenizedMessage);
99  }
100 }
void AdjustByteRangesToUtf8Ranges(std::vector< TokenRange > &ranges, const std::string &message)
Definition: chatmessageparsing.h:38
uint32_t EmoticonId
Definition: chattypes.h:24
bool SortEmoticonRangesByEmoticonId(const TokenRange &a, const TokenRange &b)
Definition: chatmessageparsing.h:34
int rangeNum
Definition: chatmessageparsing.h:53
bool ParseEmotesMessageTag(const std::string &emotesMessageTag, std::map< EmoticonId, std::vector< EmoteRange >> &result)
Definition: chatmessageparsing.h:42
Definition: chatmessageparsing.h:23
bool TokenizeLocalMessage(const std::shared_ptr< User > &user, ChannelId channelId, const std::string &message, std::string &emotesMessageTag, std::string &badgesMessageTag)
void TokenizeServerMessage(const std::string &message, const TokenizationOptions &tokenizationOptions, const std::string &messageTags, const std::shared_ptr< BitsConfiguration > &bitsConfig, const std::vector< std::string > &localUserNames, MessageInfo &tokenizedMessage)
void RemoveOverlappingRanges(std::vector< TokenRange > &ranges)
Definition: chattypes.h:293
Definition: chatmessageparsing.h:71
JSON (JavaScript Object Notation).
Definition: adsapi.h:16
int startIndex
Definition: chatmessageparsing.h:73
Definition: chatmessageparsing.h:25
bool ParseBadgesMessageTag(const std::string &messageTag, std::vector< std::pair< std::string, std::string >> &result)
TokenRangeEnum type
Definition: chatmessageparsing.h:50
bool SortTokenRangesByStartIndex(const TokenRange &a, const TokenRange &b)
void AdjustUtf8RangesToByteRanges(std::vector< TokenRange > &ranges, const std::string &message)
Definition: chatmessageparsing.h:24
uint32_t prefixLength
Definition: chatmessageparsing.h:44
uint32_t numBits
Definition: chatmessageparsing.h:45
Definition: chatmessageparsing.h:26
Definition: chatmessageparsing.h:29
bool SortTokenRangesByTypeThenRangeNum(const TokenRange &a, const TokenRange &b)
int endIndex
Definition: chatmessageparsing.h:74
Definition: chatmessageparsing.h:48
int startIndex
Definition: chatmessageparsing.h:51
int endIndex
Definition: chatmessageparsing.h:52
EmoticonId emoticonId
Definition: chatmessageparsing.h:31
uint32_t ChannelId
Definition: coretypes.h:23
bool GenerateBadgesMessageTag(const std::vector< std::pair< std::string, std::string >> &badges, std::string &result)
Definition: chattypes.h:41
TokenRangeEnum
Definition: chatmessageparsing.h:21