0

I'm making a TextEditor like Notepad and I have to "highlight" keywords of a source code in diffrent colors and fonts. My ideea is to split the sourse code and store it in an array with push_back() method, but I don't really know how to do it.

I've tried some ideeas like strtok and isstringstream , but I don't get the result. I don't know exactly how to do that. Also , I have a problem with string and AnsiString , because I'm working in C++ Builder .

Please, if someone could help me.

Best regards.

Mihaela
  • 1
  • 1
  • Here's a editing component with syntax hilighting: http://www.scintilla.org/. Might save you the trouble of re-inventing the wheel. – 001 Jan 13 '17 at 18:37
  • @JohnnyMopp What is that link about? –  Jan 13 '17 at 18:39
  • @RawN I've used that component in previous projects. Not an answer, just a suggestion. – 001 Jan 13 '17 at 18:41
  • Not an answer to your question, but this might help you chose between string and AnsiString http://utf8everywhere.org – Alan Milton Jan 13 '17 at 18:44
  • @AlexeyOmelchenko Admittedly a few years ago, when I last did serious programming for linux/freebsd, I had the impression that I am lucky to be a windows programmer by nature. As on those platforms, it appeared unheard of that something like unicode exists. That link you gave seems to be written by people with a lopsided view. The only REAL solution IMHO is that C++ adds another char type , maybe ``utf8`` and then has a specialization of ``std::basic_string`` for it, which has an api which allows iterating code points and getting proper ``length()`` vs (``char_count()``) abstractions. – BitTickler Jan 13 '17 at 19:06
  • @BitTickler When you say Unicode, as a Windows programmer, you mean multi-byte UTF-16, I guess. Today in Linux and Web worlds Unicode means multi-byte UTF-8, so there is already utf8 character type in C++. It is called 'char'. – Alan Milton Jan 13 '17 at 19:30
  • @AlexeyOmelchenko So you say ``std::string`` is aware of utf8? I don't think so. Why? Because there is only 1 length function in the class, which counts bytes and not code points. If it were aware, there would be a code point length member function or something similar, too. The support for utf8 in ``std::string`` is about as good as in a ``char mystring[20]``. Also, I am not aware of any standard C++ library functions to convert strings from and to utf8 or to verify a string is only containing valid code points etc. – BitTickler Jan 13 '17 at 19:35
  • @BitTicker Normally, you do not need codepoints. If you develop a text visualization library or a font, you need glyphs and grapheme clusters. If you develop text transmission or text processing without visualization, you need only physical size in the memory. The only area where you do need codepoints is encoding conversion. – Alan Milton Jan 13 '17 at 19:50
  • As I did syntax highlight capable txt editor in BCB before (x86,Z80,asm,basic,C++,GLSL) see for example [Normal mapping gone horribly wrong](http://stackoverflow.com/a/28541305/2521214) for screenshot and [How do I get textures to work in OpenGL?](http://stackoverflow.com/a/18672821/2521214) for win32 demo (at end of answer). You can use `AnsiString` just create function that will load line of text (`13,10` or "\r\n" separators) and load word from `AnsiString` (`" ,[]()+-*/"` separators) to parse your text line by line and word by word. Then just compare each word to syntax highlighted ones – Spektre Jan 31 '17 at 12:16
  • to obtain color and render (either use `TRichEdit` which I do not have or render directly on `Canvas` with `TextOutA` as I do but you need code whole editor on your self in such case). If you try the GLSL IDE demo you will see how the latter approch works. Key shortcuts and editation is the same as in BCB editor (rectangular selections and operation included) – Spektre Jan 31 '17 at 12:19

0 Answers0