void LLFloaterDisplayName::onSave()
{
	std::string display_name_utf8 = getChild<LLUICtrl>("display_name_editor")->getValue().asString();
	std::string display_name_confirm = getChild<LLUICtrl>("display_name_confirm")->getValue().asString();

	if (display_name_utf8.compare(display_name_confirm))
	{
		LLNotificationsUtil::add("SetDisplayNameMismatch");
		return;
	}

	const U32 DISPLAY_NAME_MAX_LENGTH = 31; // characters, not bytes
	LLWString display_name_wstr = utf8string_to_wstring(display_name_utf8);
	if (display_name_wstr.size() > DISPLAY_NAME_MAX_LENGTH)
	{
		LLSD args;
		args["LENGTH"] = llformat("%d", DISPLAY_NAME_MAX_LENGTH);
		LLNotificationsUtil::add("SetDisplayNameFailedLength", args);
		return;
	}
	
	if (LLAvatarNameCache::hasNameLookupURL())
	{
		LLViewerDisplayName::set(display_name_utf8, boost::bind(&LLFloaterDisplayName::onCacheSetName, this, _1, _2, _3));	
	}
	else
	{
		LLNotificationsUtil::add("SetDisplayNameFailedGeneric");
	}

	setVisible(false);
}
void LLHUDNameTag::addLabel(const std::string& label_utf8)
{
	LLWString wstr = utf8string_to_wstring(label_utf8);
	if (!wstr.empty())
	{
		LLWString seps(utf8str_to_wstring("\r\n"));
		LLWString empty;

		typedef boost::tokenizer<boost::char_separator<llwchar>, LLWString::const_iterator, LLWString > tokenizer;
		boost::char_separator<llwchar> sep(seps.c_str(), empty.c_str(), boost::keep_empty_tokens);

		tokenizer tokens(wstr, sep);
		tokenizer::iterator iter = tokens.begin();

		while (iter != tokens.end())
		{
			U32 line_length = 0;
			do	
			{
				S32 segment_length = mFontp->maxDrawableChars(iter->substr(line_length).c_str(), 
					HUD_TEXT_MAX_WIDTH, wstr.length(), LLFontGL::WORD_BOUNDARY_IF_POSSIBLE);
				LLHUDTextSegment segment(iter->substr(line_length, segment_length), LLFontGL::NORMAL, mColor, mFontp);
				mLabelSegments.push_back(segment);
				line_length += segment_length;
			}
			while (line_length != iter->size());
			++iter;
		}
	}
}