Numworks Epsilon  1.4.1
Graphing Calculator Operating System
toolbox_helpers.cpp
Go to the documentation of this file.
1 #include "toolbox_helpers.h"
2 #include <string.h>
3 
4 namespace Shared {
5 namespace ToolboxHelpers {
6 
7 int CursorIndexInCommand(const char * text) {
8  for (size_t i = 0; i < strlen(text); i++) {
9  if (text[i] == '(' || text[i] == '\'') {
10  return i + 1;
11  }
12  }
13  return strlen(text);
14 }
15 
16 void TextToInsertForCommandMessage(I18n::Message message, char * buffer) {
17  const char * messageText = I18n::translate(message);
18  TextToInsertForCommandText(messageText, buffer);
19 }
20 
21 void TextToInsertForCommandText(const char * command, char * buffer) {
22  int currentNewTextIndex = 0;
23  int numberOfOpenBrackets = 0;
24  bool insideQuote = false;
25  size_t commandLength = strlen(command);
26  for (size_t i = 0; i < commandLength; i++) {
27  if (command[i] == ')') {
28  numberOfOpenBrackets--;
29  }
30  if ((numberOfOpenBrackets == 0 || command[i] == ',') && (!insideQuote || command[i] == '\'')) {
31  buffer[currentNewTextIndex++] = command[i];
32  }
33  if (command[i] == '(') {
34  numberOfOpenBrackets++;
35  }
36  if (command[i] == '\'') {
37  insideQuote = !insideQuote;
38  }
39  }
40  buffer[currentNewTextIndex] = 0;
41 }
42 
43 }
44 }
void TextToInsertForCommandText(const char *command, char *buffer)
enum Message uint16_t enum Language uint16_t const char * translate(Message m, Language l=(Language) 0)
Definition: i18n.cpp:5
int CursorIndexInCommand(const char *text)
void TextToInsertForCommandMessage(I18n::Message message, char *buffer)
size_t strlen(const char *s)
Definition: strlen.c:3