PageRenderTime 36ms CodeModel.GetById 16ms 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
Possible License(s): LGPL-2.1
  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. #include "lltextutil.h"
  27. #include "lluicolor.h"
  28. #include "lltextbox.h"
  29. #include "llurlmatch.h"
  30. boost::function<bool(LLUrlMatch*,LLTextBase*)> LLTextUtil::TextHelpers::iconCallbackCreationFunction = 0;
  31. void LLTextUtil::textboxSetHighlightedVal(LLTextBox *txtbox, const LLStyle::Params& normal_style, const std::string& text, const std::string& hl)
  32. {
  33. static LLUIColor sFilterTextColor = LLUIColorTable::instance().getColor("FilterTextColor", LLColor4::green);
  34. std::string text_uc = text;
  35. LLStringUtil::toUpper(text_uc);
  36. size_t hl_begin = 0, hl_len = hl.size();
  37. if (hl_len == 0 || (hl_begin = text_uc.find(hl)) == std::string::npos)
  38. {
  39. txtbox->setText(text, normal_style);
  40. return;
  41. }
  42. LLStyle::Params hl_style = normal_style;
  43. hl_style.color = sFilterTextColor;
  44. txtbox->setText(LLStringUtil::null); // clear text
  45. txtbox->appendText(text.substr(0, hl_begin), false, normal_style);
  46. txtbox->appendText(text.substr(hl_begin, hl_len), false, hl_style);
  47. txtbox->appendText(text.substr(hl_begin + hl_len), false, normal_style);
  48. }
  49. const std::string& LLTextUtil::formatPhoneNumber(const std::string& phone_str)
  50. {
  51. static const std::string PHONE_SEPARATOR = LLUI::sSettingGroups["config"]->getString("AvalinePhoneSeparator");
  52. static const S32 PHONE_PART_LEN = 2;
  53. static std::string formatted_phone_str;
  54. formatted_phone_str = phone_str;
  55. S32 separator_pos = (S32)(formatted_phone_str.size()) - PHONE_PART_LEN;
  56. for (; separator_pos >= PHONE_PART_LEN; separator_pos -= PHONE_PART_LEN)
  57. {
  58. formatted_phone_str.insert(separator_pos, PHONE_SEPARATOR);
  59. }
  60. return formatted_phone_str;
  61. }
  62. bool LLTextUtil::processUrlMatch(LLUrlMatch* match,LLTextBase* text_base)
  63. {
  64. if (match == 0 || text_base == 0)
  65. return false;
  66. if(match->getID() != LLUUID::null && TextHelpers::iconCallbackCreationFunction)
  67. {
  68. bool segment_created = TextHelpers::iconCallbackCreationFunction(match,text_base);
  69. if(segment_created)
  70. return true;
  71. }
  72. // output an optional icon before the Url
  73. if (!match->getIcon().empty() )
  74. {
  75. LLUIImagePtr image = LLUI::getUIImage(match->getIcon());
  76. if (image)
  77. {
  78. LLStyle::Params icon;
  79. icon.image = image;
  80. // Text will be replaced during rendering with the icon,
  81. // but string cannot be empty or the segment won't be
  82. // added (or drawn).
  83. text_base->appendImageSegment(icon);
  84. return true;
  85. }
  86. }
  87. return false;
  88. }
  89. // EOF