llkeywords.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /**
  2. * @file llkeywords.h
  3. * @brief Keyword list for LSL
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLKEYWORDS_H
  33. #define LL_LLKEYWORDS_H
  34. #include <map>
  35. #include <list>
  36. #include <deque>
  37. #include "llstring.h"
  38. #include "llpreprocessor.h"
  39. #include "llcolor3.h"
  40. class LLTextSegment;
  41. class LLKeywordToken
  42. {
  43. public:
  44. enum TOKEN_TYPE { WORD, LINE, TWO_SIDED_DELIMITER, ONE_SIDED_DELIMITER };
  45. LLKeywordToken(TOKEN_TYPE type, const LLColor3& color,
  46. const LLWString& token, const LLWString& tool_tip)
  47. : mType(type),
  48. mToken(token),
  49. mColor(color),
  50. mToolTip(tool_tip)
  51. {
  52. }
  53. bool isHead(const llwchar* s, bool search_end_c_comment = false) const;
  54. LL_INLINE S32 getLength() const { return mToken.size(); }
  55. LL_INLINE const LLWString& getToken() const { return mToken; }
  56. LL_INLINE const LLColor3& getColor() const { return mColor; }
  57. LL_INLINE TOKEN_TYPE getType() const { return mType; }
  58. LL_INLINE const LLWString& getToolTip() const { return mToolTip; }
  59. #if LL_DEBUG
  60. void dump();
  61. #endif
  62. private:
  63. TOKEN_TYPE mType;
  64. LLWString mToken;
  65. LLColor3 mColor;
  66. LLWString mToolTip;
  67. };
  68. class LLKeywords
  69. {
  70. protected:
  71. LOG_CLASS(LLKeywords);
  72. public:
  73. LLKeywords();
  74. ~LLKeywords();
  75. bool loadFromFile(const std::string& filename);
  76. LL_INLINE bool isLoaded() const { return mLoaded; }
  77. void findSegments(std::vector<LLTextSegment*>* seg_list,
  78. const LLWString& text, const LLColor4& default_color);
  79. // Add the token as described
  80. void addToken(LLKeywordToken::TOKEN_TYPE type, const std::string& key,
  81. const LLColor3& color,
  82. const std::string& tool_tip = LLStringUtil::null);
  83. typedef std::map<LLWString, LLKeywordToken*> word_token_map_t;
  84. typedef word_token_map_t::const_iterator keyword_iterator_t;
  85. LL_INLINE keyword_iterator_t begin() const { return mWordTokenMap.begin(); }
  86. LL_INLINE keyword_iterator_t end() const { return mWordTokenMap.end(); }
  87. #if LL_DEBUG
  88. void dump();
  89. #endif
  90. private:
  91. LLColor3 readColor(const std::string& s);
  92. void insertSegment(std::vector<LLTextSegment*>* seg_list,
  93. LLTextSegment* new_segment, S32 text_len,
  94. const LLColor4& default_color);
  95. private:
  96. word_token_map_t mWordTokenMap;
  97. typedef std::deque<LLKeywordToken*> token_list_t;
  98. token_list_t mLineTokenList;
  99. token_list_t mDelimiterTokenList;
  100. bool mLoaded;
  101. };
  102. #endif // LL_LLKEYWORDS_H