Fcitx
text.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2016-2016 CSSlayer <wengxt@gmail.com>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 #ifndef _FCITX_TEXT_H_
8 #define _FCITX_TEXT_H_
9 
10 #include <memory>
11 #include <ostream>
12 #include <string>
13 #include <vector>
14 #include <fcitx-utils/macros.h>
16 #include <fcitx/fcitxcore_export.h>
17 
18 /// \addtogroup FcitxCore
19 /// \{
20 /// \file
21 /// \brief Formatted string commonly used in user interface.
22 
23 namespace fcitx {
24 class TextPrivate;
25 
26 /// A class represents a formatted string.
27 class FCITXCORE_EXPORT Text {
28 public:
29  Text();
30  explicit Text(std::string text,
31  TextFormatFlags flag = TextFormatFlag::NoFlag);
32  FCITX_DECLARE_VIRTUAL_DTOR_COPY_AND_MOVE(Text);
33 
34  /// Get cursor by byte.
35  int cursor() const;
36  /// Set cursor by byte.
37  void setCursor(int pos = -1);
38  void clear();
39  void append(std::string str, TextFormatFlags flag = TextFormatFlag::NoFlag);
40  /**
41  * Append another text.
42  *
43  * @param text text to append
44  * @since 5.1.9
45  */
46  void append(Text text);
47  const std::string &stringAt(int idx) const;
48  TextFormatFlags formatAt(int idx) const;
49  size_t size() const;
50  bool empty() const;
51  size_t textLength() const;
52  std::string toString() const;
53  std::string toStringForCommit() const;
54 
55  /**
56  * Remove empty string piece and merge the string with same format.
57  *
58  * This function is useful for frontend to send less data over the wire and
59  * avoid send data that is problematic for some frontend.
60  *
61  * @since 5.1.1
62  */
63  Text normalize() const;
64 
65  /**
66  * Split Text object into lines.
67  *
68  * @return lines.
69  * @since 5.0.6
70  */
71  std::vector<Text> splitByLine() const;
72 
73 private:
74  std::unique_ptr<TextPrivate> d_ptr;
75  FCITX_DECLARE_PRIVATE(Text);
76 };
77 
78 FCITXCORE_EXPORT std::ostream &operator<<(std::ostream &os, const Text &text);
79 
80 } // namespace fcitx
81 
82 #endif // _FCITX_TEXT_H_
Definition: action.cpp:17
A class represents a formatted string.
Definition: text.h:27
Enum flag for text formatting.
Class provides bit flag support for Enum.
Definition: flags.h:33