PageRenderTime 48ms CodeModel.GetById 40ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/lltextutil.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 107 lines | 59 code | 18 blank | 30 comment | 15 complexity | 45ac03220e617ebc0941658037e9c1f8 MD5 | raw file
  1/** 
  2 * @file lltextutil.cpp
  3 * @brief Misc text-related auxiliary methods
  4 *
  5 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "lltextutil.h"
 28
 29#include "lluicolor.h"
 30#include "lltextbox.h"
 31#include "llurlmatch.h"
 32
 33boost::function<bool(LLUrlMatch*,LLTextBase*)>	LLTextUtil::TextHelpers::iconCallbackCreationFunction = 0;
 34
 35void LLTextUtil::textboxSetHighlightedVal(LLTextBox *txtbox, const LLStyle::Params& normal_style, const std::string& text, const std::string& hl)
 36{
 37	static LLUIColor sFilterTextColor = LLUIColorTable::instance().getColor("FilterTextColor", LLColor4::green);
 38
 39	std::string text_uc = text;
 40	LLStringUtil::toUpper(text_uc);
 41
 42	size_t hl_begin = 0, hl_len = hl.size();
 43
 44	if (hl_len == 0 || (hl_begin = text_uc.find(hl)) == std::string::npos)
 45	{
 46		txtbox->setText(text, normal_style);
 47		return;
 48	}
 49
 50	LLStyle::Params hl_style = normal_style;
 51	hl_style.color = sFilterTextColor;
 52
 53	txtbox->setText(LLStringUtil::null); // clear text
 54	txtbox->appendText(text.substr(0, hl_begin),		false, normal_style);
 55	txtbox->appendText(text.substr(hl_begin, hl_len),	false, hl_style);
 56	txtbox->appendText(text.substr(hl_begin + hl_len),	false, normal_style);
 57}
 58
 59const std::string& LLTextUtil::formatPhoneNumber(const std::string& phone_str)
 60{
 61	static const std::string PHONE_SEPARATOR = LLUI::sSettingGroups["config"]->getString("AvalinePhoneSeparator");
 62	static const S32 PHONE_PART_LEN = 2;
 63
 64	static std::string formatted_phone_str;
 65	formatted_phone_str = phone_str;
 66	S32 separator_pos = (S32)(formatted_phone_str.size()) - PHONE_PART_LEN;
 67	for (; separator_pos >= PHONE_PART_LEN; separator_pos -= PHONE_PART_LEN)
 68	{
 69		formatted_phone_str.insert(separator_pos, PHONE_SEPARATOR);
 70	}
 71
 72	return formatted_phone_str;
 73}
 74
 75bool LLTextUtil::processUrlMatch(LLUrlMatch* match,LLTextBase* text_base)
 76{
 77	if (match == 0 || text_base == 0)
 78		return false;
 79
 80	if(match->getID() != LLUUID::null && TextHelpers::iconCallbackCreationFunction)
 81	{
 82		bool segment_created = TextHelpers::iconCallbackCreationFunction(match,text_base);
 83		if(segment_created)
 84			return true;
 85	}
 86
 87	// output an optional icon before the Url
 88	if (!match->getIcon().empty() )
 89	{
 90		LLUIImagePtr image = LLUI::getUIImage(match->getIcon());
 91		if (image)
 92		{
 93			LLStyle::Params icon;
 94			icon.image = image;
 95			// Text will be replaced during rendering with the icon,
 96			// but string cannot be empty or the segment won't be
 97			// added (or drawn).
 98			text_base->appendImageSegment(icon);
 99
100			return true;
101		}
102	}
103	
104	return false;
105}
106
107// EOF