Make string splitting code generally available so it can be reused elsehwere
--HG-- branch : RLVameow-7.2.2
parent
3be78776f4
commit
4a07c81196
|
|
@ -611,6 +611,41 @@ std::string utf8str_substr(const std::string& utf8str, const S32 index, const S3
|
|||
return utf8str.substr(index, cur_char);
|
||||
}
|
||||
}
|
||||
|
||||
void utf8str_split(std::list<std::string>& split_list, const std::string& utf8str, size_t maxlen, char split_token)
|
||||
{
|
||||
split_list.clear();
|
||||
|
||||
std::string::size_type lenMsg = utf8str.length(), lenIt = 0;
|
||||
|
||||
const char* pstrIt = utf8str.c_str(); std::string strTemp;
|
||||
while (lenIt < lenMsg)
|
||||
{
|
||||
if (lenIt + maxlen < lenMsg)
|
||||
{
|
||||
// Find the last split character
|
||||
const char* pstrTemp = pstrIt + maxlen;
|
||||
while ( (pstrTemp > pstrIt) && (*pstrTemp != split_token) )
|
||||
pstrTemp--;
|
||||
|
||||
if (pstrTemp > pstrIt)
|
||||
strTemp = utf8str.substr(lenIt, pstrTemp - pstrIt);
|
||||
else
|
||||
strTemp = utf8str_substr(utf8str, lenIt, maxlen);
|
||||
}
|
||||
else
|
||||
{
|
||||
strTemp = utf8str.substr(lenIt, std::string::npos);
|
||||
}
|
||||
|
||||
split_list.push_back(strTemp);
|
||||
|
||||
lenIt += strTemp.length();
|
||||
pstrIt = utf8str.c_str() + lenIt;
|
||||
if (*pstrIt == split_token)
|
||||
lenIt++;
|
||||
}
|
||||
}
|
||||
// [/RLVa:KB]
|
||||
|
||||
std::string utf8str_symbol_truncate(const std::string& utf8str, const S32 symbol_len)
|
||||
|
|
|
|||
|
|
@ -35,6 +35,9 @@
|
|||
#include <vector>
|
||||
#include <map>
|
||||
#include "llformat.h"
|
||||
// [RLVa:KB] - Checked: RLVa-2.1.0
|
||||
#include <list>
|
||||
// [/RLVa:KB]
|
||||
|
||||
#if LL_LINUX || LL_SOLARIS
|
||||
#include <wctype.h>
|
||||
|
|
@ -559,6 +562,7 @@ LL_COMMON_API std::string utf8str_truncate(const std::string& utf8str, const S32
|
|||
|
||||
// [RLVa:KB] - Checked: RLVa-2.1.0
|
||||
LL_COMMON_API std::string utf8str_substr(const std::string& utf8str, const S32 index, const S32 max_len);
|
||||
LL_COMMON_API void utf8str_split(std::list<std::string>& split_list, const std::string& utf8str, size_t maxlen, char split_token);
|
||||
// [/RLVa:KB]
|
||||
|
||||
LL_COMMON_API std::string utf8str_trim(const std::string& utf8str);
|
||||
|
|
|
|||
|
|
@ -613,28 +613,10 @@ void RlvUtil::sendIMMessage(const LLUUID& idRecipient, const std::string& strMsg
|
|||
std::string strAgentName;
|
||||
LLAgentUI::buildFullname(strAgentName);
|
||||
|
||||
std::string::size_type lenMsg = strMsg.length(), lenIt = 0;
|
||||
|
||||
const char* pstrIt = strMsg.c_str(); std::string strTemp;
|
||||
while (lenIt < lenMsg)
|
||||
std::list<std::string> msgList;
|
||||
utf8str_split(msgList, strMsg, MAX_MSG_STR_LEN, chSplit);
|
||||
for (const std::string& strMsg : msgList)
|
||||
{
|
||||
if (lenIt + MAX_MSG_STR_LEN < lenMsg)
|
||||
{
|
||||
// Find the last split character
|
||||
const char* pstrTemp = pstrIt + MAX_MSG_STR_LEN;
|
||||
while ( (pstrTemp > pstrIt) && (*pstrTemp != chSplit) )
|
||||
pstrTemp--;
|
||||
|
||||
if (pstrTemp > pstrIt)
|
||||
strTemp = strMsg.substr(lenIt, pstrTemp - pstrIt);
|
||||
else
|
||||
strTemp = utf8str_substr(strMsg, lenIt, MAX_MSG_STR_LEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
strTemp = strMsg.substr(lenIt, std::string::npos);
|
||||
}
|
||||
|
||||
pack_instant_message(
|
||||
gMessageSystem,
|
||||
gAgent.getID(),
|
||||
|
|
@ -642,16 +624,11 @@ void RlvUtil::sendIMMessage(const LLUUID& idRecipient, const std::string& strMsg
|
|||
gAgent.getSessionID(),
|
||||
idRecipient,
|
||||
strAgentName.c_str(),
|
||||
strTemp.c_str(),
|
||||
( (!pBuddyInfo) || (pBuddyInfo->isOnline()) ) ? IM_ONLINE : IM_OFFLINE,
|
||||
strMsg.c_str(),
|
||||
((!pBuddyInfo) || (pBuddyInfo->isOnline())) ? IM_ONLINE : IM_OFFLINE,
|
||||
IM_NOTHING_SPECIAL,
|
||||
idSession);
|
||||
gAgent.sendReliableMessage();
|
||||
|
||||
lenIt += strTemp.length();
|
||||
pstrIt = strMsg.c_str() + lenIt;
|
||||
if (*pstrIt == chSplit)
|
||||
lenIt++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue