Blame view

build3/apps/shared/toolbox_helpers.cpp 1.1 KB
6663b6c9   adorian   projet complet av...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  #include "toolbox_helpers.h"
  #include <string.h>
  
  namespace Shared {
  namespace ToolboxHelpers {
  
  int CursorIndexInCommand(const char * text) {
    for (size_t i = 0; i < strlen(text); i++) {
      if (text[i] == '(' || text[i] == '\'') {
        return i + 1;
      }
    }
    return strlen(text);
  }
  
  void TextToInsertForCommandMessage(I18n::Message message, char * buffer) {
    const char * messageText = I18n::translate(message);
    TextToInsertForCommandText(messageText, buffer);
  }
  
  void TextToInsertForCommandText(const char * command, char * buffer) {
    int currentNewTextIndex = 0;
    int numberOfOpenBrackets = 0;
    bool insideQuote = false;
    size_t commandLength = strlen(command);
    for (size_t i = 0; i < commandLength; i++) {
      if (command[i] == ')') {
        numberOfOpenBrackets--;
      }
      if ((numberOfOpenBrackets == 0 || command[i] == ',') && (!insideQuote || command[i] == '\'')) {
        buffer[currentNewTextIndex++] = command[i];
      }
      if (command[i] == '(') {
        numberOfOpenBrackets++;
      }
      if (command[i] == '\'') {
        insideQuote = !insideQuote;
      }
    }
    buffer[currentNewTextIndex] = 0;
  }
  
  }
  }