Parse wire
Todas as funções ficam no namespace wire.
⚖️ nameEq
Section titled “⚖️ nameEq”Compara duas strings C por igualdade.
bool a = wire::nameEq("help", cmd.name);📝 Sintaxe
Section titled “📝 Sintaxe”bool nameEq(const char* a, const char* b)⏱ Complexidade
Section titled “⏱ Complexidade”O(n) no comprimento das strings.
✂️ trimView
Section titled “✂️ trimView”Retorna o intervalo [a, b) sem espaços em branco no início ou no fim de s[0..n).
📝 Sintaxe
Section titled “📝 Sintaxe”void trimView(const char* s, size_t n, size_t& a, size_t& b)⏱ Complexidade
Section titled “⏱ Complexidade”O(n).
🔪 splitTopLevel
Section titled “🔪 splitTopLevel”Divide s[0..n) em segmentos no delimitador delim, sem dividir dentro de parênteses aninhados ou strings entre aspas "...".
📝 Sintaxe
Section titled “📝 Sintaxe”bool splitTopLevel(const char* s, size_t n, char delim, std::vector<std::pair<size_t, size_t>>& ranges)🔮 Exemplo
Section titled “🔮 Exemplo”std::vector<std::pair<size_t, size_t>> ranges;wire::splitTopLevel("a;b;c", 5, ';', ranges);// ranges: [0,1), [2,3), [4,5)⏱ Complexidade
Section titled “⏱ Complexidade”O(n).
🎯 findMatchingClose
Section titled “🎯 findMatchingClose”Localiza o ) de fechamento que corresponde ao ( em openIdx, respeitando strings e aninhamento.
📝 Sintaxe
Section titled “📝 Sintaxe”bool findMatchingClose(const char* s, size_t openIdx, size_t n, size_t& closeIdx)⏱ Complexidade
Section titled “⏱ Complexidade”O(n) a partir de openIdx.
🔓 unquoteField
Section titled “🔓 unquoteField”Remove aspas ao redor e desfaz escapes de \\ e \" em out. Tokens sem aspas são copiados após trim, como estão.
📝 Sintaxe
Section titled “📝 Sintaxe”bool unquoteField(const char* src, size_t len, char* out, size_t outCap)🔮 Exemplo
Section titled “🔮 Exemplo”char buf[wire::kArgCap];wire::unquoteField("\"hello \\\"world\\\"\"", 18, buf, sizeof(buf));// buf == "hello \"world\""⏱ Complexidade
Section titled “⏱ Complexidade”O(len).
📋 copyTokenToArgv
Section titled “📋 copyTokenToArgv”Copia um token bruto para cmd.argv[idx] após unquoteField.
📝 Sintaxe
Section titled “📝 Sintaxe”bool copyTokenToArgv(Command& cmd, int idx, const char* src, size_t len)Retorna false se idx estiver fora do intervalo ou o token exceder kArgCap.
⏱ Complexidade
Section titled “⏱ Complexidade”O(len).
🔢 tokenIsPlainInteger
Section titled “🔢 tokenIsPlainInteger”Retorna true se s for um inteiro decimal, opcionalmente negativo (ex.: 42, -7).
📝 Sintaxe
Section titled “📝 Sintaxe”bool tokenIsPlainInteger(const char* s)⏱ Complexidade
Section titled “⏱ Complexidade”O(n).
🏷️ tokenIsPlainIdentifier
Section titled “🏷️ tokenIsPlainIdentifier”Retorna true se s for um identificador C válido ([a-zA-Z_][a-zA-Z0-9_]*).
📝 Sintaxe
Section titled “📝 Sintaxe”bool tokenIsPlainIdentifier(const char* s)⏱ Complexidade
Section titled “⏱ Complexidade”O(n).
❓ tokenNeedsQuotes
Section titled “❓ tokenNeedsQuotes”Retorna true se s precisar de aspas na serialização (não for inteiro nem identificador puro).
📝 Sintaxe
Section titled “📝 Sintaxe”bool tokenNeedsQuotes(const char* s)⏱ Complexidade
Section titled “⏱ Complexidade”O(n).
🔢 parseFloat
Section titled “🔢 parseFloat”Converte uma string em float. Retorna false para entrada nula, vazia ou inválida.
📝 Sintaxe
Section titled “📝 Sintaxe”bool parseFloat(const char* s, float& out)🔮 Exemplo
Section titled “🔮 Exemplo”float v;wire::parseFloat("3.14", v); // v == 3.14f⏱ Complexidade
Section titled “⏱ Complexidade”O(n).
🔢 parseInt
Section titled “🔢 parseInt”Converte uma string em int na base 10. Retorna false para entrada nula, vazia ou inválida.
📝 Sintaxe
Section titled “📝 Sintaxe”bool parseInt(const char* s, int& out)⏱ Complexidade
Section titled “⏱ Complexidade”O(n).
📄 parseSegment
Section titled “📄 parseSegment”Faz parse de um segmento wire nome(modo,role,...) (ponto e vírgula opcional) em um Command.
📝 Sintaxe
Section titled “📝 Sintaxe”bool parseSegment(const char* seg, size_t segLen, Command& out)🔮 Exemplo
Section titled “🔮 Exemplo”wire::Command cmd;wire::parseSegment("help(s,r)", 9, cmd);// cmd.name == "help", cmd.mode == 's', cmd.role == 'r'⏱ Complexidade
Section titled “⏱ Complexidade”O(segLen).
📨 parseMessage
Section titled “📨 parseMessage”Faz parse de uma mensagem completa com um ou mais comandos separados por ;.
📝 Sintaxe
Section titled “📝 Sintaxe”bool parseMessage(const char* msg, std::vector<Command>& out)🔮 Exemplo
Section titled “🔮 Exemplo”std::vector<wire::Command> commands;wire::parseMessage("help(s,r);param_list(s,r);", commands);// commands.size() == 2Retorna false se msg for nulo ou algum segmento for inválido.
⏱ Complexidade
Section titled “⏱ Complexidade”O(|msg|).
📑 parseListHeader
Section titled “📑 parseListHeader”Extrai T, C, B, j de um comando header parseado (mode == 'h', pelo menos 6 entradas em argv).
📝 Sintaxe
Section titled “📝 Sintaxe”bool parseListHeader(const Command& cmd, ListHeader& hdr)🔮 Exemplo
Section titled “🔮 Exemplo”// param_list(h,s,5,1,1,0);wire::ListHeader hdr;wire::parseListHeader(cmd, hdr);// hdr.T == 5, hdr.C == 1, hdr.B == 1, hdr.j == 0⏱ Complexidade
Section titled “⏱ Complexidade”O(1).
🔤 commandKeyLower
Section titled “🔤 commandKeyLower”Normaliza o nome de um comando para minúsculas para busca case-insensitive.
📝 Sintaxe
Section titled “📝 Sintaxe”std::string commandKeyLower(const char* name)🔮 Exemplo
Section titled “🔮 Exemplo”std::string key = wire::commandKeyLower("Param_List");// key == "param_list"⏱ Complexidade
Section titled “⏱ Complexidade”O(n).