MCPcopy Create free account
hub / github.com/The-Powder-Toy/The-Powder-Toy / highlight

Function highlight

src/lua/LuaScriptInterface.cpp:621–795  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

619}
620
621static String highlight(String command)
622{
623 StringBuilder result;
624 int pos = 0;
625 String::value_type const*raw = command.c_str();
626 String::value_type c;
627 while ((c = raw[pos]))
628 {
629 if((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_')
630 {
631 int len = 0;
632 String::value_type w;
633 String::value_type const* wstart = raw+pos;
634 while((w = wstart[len]) && ((w >= 'A' && w <= 'Z') || (w >= 'a' && w <= 'z') || (w >= '0' && w <= '9') || w == '_'))
635 len++;
636#define CMP(X) (String(wstart, len) == X)
637 if(CMP("and") || CMP("break") || CMP("do") || CMP("else") || CMP("elseif") || CMP("end") || CMP("for") || CMP("function") || CMP("if") || CMP("in") || CMP("local") || CMP("not") || CMP("or") || CMP("repeat") || CMP("return") || CMP("then") || CMP("until") || CMP("while"))
638 result << "\x0F\xB5\x89\x01" << String(wstart, len) << "\bw";
639 else if(CMP("false") || CMP("nil") || CMP("true"))
640 result << "\x0F\xCB\x4B\x16" << String(wstart, len) << "\bw";
641 else
642 result << "\x0F\x2A\xA1\x98" << String(wstart, len) << "\bw";
643#undef CMP
644 pos += len;
645 }
646 else if((c >= '0' && c <= '9') || (c == '.' && raw[pos + 1] >= '0' && raw[pos + 1] <= '9'))
647 {
648 if(c == '0' && raw[pos + 1] == 'x')
649 {
650 int len = 2;
651 String::value_type w;
652 String::value_type const* wstart = raw+pos;
653 while((w = wstart[len]) && ((w >= '0' && w <= '9') || (w >= 'A' && w <= 'F') || (w >= 'a' && w <= 'f')))
654 len++;
655 result << "\x0F\xD3\x36\x82" << String(wstart, len) << "\bw";
656 pos += len;
657 }
658 else
659 {
660 int len = 0;
661 String::value_type w;
662 String::value_type const* wstart = raw+pos;
663 bool seendot = false;
664 while((w = wstart[len]) && ((w >= '0' && w <= '9') || w == '.'))
665 {
666 if(w == '.')
667 {
668 if(seendot)
669 break;
670 else
671 seendot = true;
672 }
673 len++;
674 }
675 if(w == 'e')
676 {
677 len++;
678 w = wstart[len];

Callers 1

FormatCommandMethod · 0.85

Calls 2

StringClass · 0.85
BuildMethod · 0.60

Tested by

no test coverage detected