Click here to Skip to main content
15,887,322 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Wordle 356 Pin
dan!sh 9-Jun-22 23:39
professional dan!sh 9-Jun-22 23:39 
GeneralRe: Wordle 356 Pin
Greg Utas10-Jun-22 0:17
professionalGreg Utas10-Jun-22 0:17 
GeneralRe: Wordle 356 Pin
Cp-Coder10-Jun-22 1:29
Cp-Coder10-Jun-22 1:29 
GeneralRe: Wordle 356 Pin
musefan10-Jun-22 1:34
musefan10-Jun-22 1:34 
NewsInteresting MS Video Pin
Super Lloyd9-Jun-22 13:01
Super Lloyd9-Jun-22 13:01 
GeneralI'm feeling "diverse" today Pin
honey the codewitch9-Jun-22 11:29
mvahoney the codewitch9-Jun-22 11:29 
GeneralRe: I'm feeling "diverse" today Pin
Sander Rossel9-Jun-22 20:57
professionalSander Rossel9-Jun-22 20:57 
GeneralRe: I'm feeling "diverse" today Pin
honey the codewitch9-Jun-22 22:03
mvahoney the codewitch9-Jun-22 22:03 
Sander Rossel wrote:
Also not sure about the nature of your project, but when an employee of mine would use regex, that no one knows or expects in a web API scenario, in favor of JSON, which everyone knows and expects in that scenario, I'd have a very serious talk with him


So would I, because he's working on machines with gobs of RAM and CPU to spare, and hardware is typically cheaper than software, especially software that's written predictably.

Here's my current reality:
RAM:   [==        ]  20.6% (used 67656 bytes from 327680 bytes)
Flash: [=======   ]  65.1% (used 852905 bytes from 1310720 bytes)


I don't have the flash space for a JSON lib.

So with IoT, priorities change. If I had your priorities, my code wouldn't even run.

Sander Rossel wrote:
I'm also not sure why JSON would be a dependency while regex is not


Because I am not using a regex engine. I am precomputing a regular expression into an array.

Then I use some simple code to traverse that array in order to match

For example:

C++
// \"unixtime\"[\t \r\n]*:[\t \r\n]*
int16_t wtime_unix_time_dfa_table[] PROGMEM = {
        -1, 1, 6, 1, 34, 34, -1, 1, 12, 1, 117, 117, -1, 1, 18,
        1, 110, 110, -1, 1, 24, 1, 105, 105, -1, 1, 30, 1, 120, 120,
        -1, 1, 36, 1, 116, 116, -1, 1, 42, 1, 105, 105, -1, 1, 48,
        1, 109, 109, -1, 1, 54, 1, 101, 101, -1, 1, 60, 1, 34, 34,
        -1, 2, 60, 3, 9, 10, 13, 13, 32, 32, 74, 1, 58, 58, 0,
        1, 74, 3, 9, 10, 13, 13, 32, 32
};


In order to match with it, I run this code:

C++
// runs a dfa state machine match algorithm
bool wtime_fa_match(const int16_t* dfa, int16_t(read_cb)(void*), void* cb_state = nullptr) {
    int tlen;
    int tto;
    int prlen;
    int pmin;
    int pmax;
    int i;
    int j;
    int ch;
    int state = 0;
    bool done;
    bool found = false;
    int acc = -1;
    ch = read_cb(cb_state);
    while (ch != -1) {
        acc = -1;
        done = false;
        while (!done) {
        start_dfa:
            done = true;
            acc = (int16_t)pgm_read_word(dfa+(state++));
            tlen = (int16_t)pgm_read_word(dfa+(state++));
            for (i = 0; i < tlen; ++i) {
                tto = (int16_t)pgm_read_word(dfa+(state++));
                prlen = (int16_t)pgm_read_word(dfa+(state++));
                for (j = 0; j < prlen; ++j) {
                    pmin = (int16_t)pgm_read_word(dfa+(state++));
                    pmax = (int16_t)pgm_read_word(dfa+(state++));
                    if (ch < pmin) break;
                    if (ch <= pmax) {
                        found = true;
                        ch = read_cb(cb_state);
                        state = tto;
                        done = false;
                        goto start_dfa;
                    }
                }
            }
        }
        if (acc != -1) {
            return found;
        }
        ch = read_cb(cb_state);
        state = 0;
    }
    return false;
}

To err is human. Fortune favors the monsters.


modified 10-Jun-22 4:11am.

GeneralRe: I'm feeling "diverse" today Pin
Sander Rossel10-Jun-22 1:33
professionalSander Rossel10-Jun-22 1:33 
GeneralRe: I'm feeling "diverse" today Pin
klinkenbecker10-Jun-22 2:36
klinkenbecker10-Jun-22 2:36 
GeneralRe: I'm feeling "diverse" today Pin
honey the codewitch10-Jun-22 2:38
mvahoney the codewitch10-Jun-22 2:38 
GeneralRe: I'm feeling "diverse" today Pin
klinkenbecker10-Jun-22 3:21
klinkenbecker10-Jun-22 3:21 
GeneralRe: I'm feeling "diverse" today Pin
honey the codewitch10-Jun-22 3:56
mvahoney the codewitch10-Jun-22 3:56 
GeneralRe: I'm feeling "diverse" today Pin
klinkenbecker10-Jun-22 7:27
klinkenbecker10-Jun-22 7:27 
GeneralRe: I'm feeling "diverse" today Pin
honey the codewitch10-Jun-22 8:56
mvahoney the codewitch10-Jun-22 8:56 
GeneralRe: I'm feeling "diverse" today Pin
klinkenbecker10-Jun-22 12:03
klinkenbecker10-Jun-22 12:03 
QuestionRe: I'm feeling "diverse" today Pin
megaadam10-Jun-22 3:48
professionalmegaadam10-Jun-22 3:48 
AnswerRe: I'm feeling "diverse" today Pin
honey the codewitch10-Jun-22 3:55
mvahoney the codewitch10-Jun-22 3:55 
GeneralRe: I'm feeling "diverse" today Pin
megaadam10-Jun-22 4:15
professionalmegaadam10-Jun-22 4:15 
GeneralRe: I'm feeling "diverse" today Pin
honey the codewitch10-Jun-22 6:30
mvahoney the codewitch10-Jun-22 6:30 
GeneralRe: I'm feeling "diverse" today Pin
megaadam10-Jun-22 6:13
professionalmegaadam10-Jun-22 6:13 
GeneralRe: I'm feeling "diverse" today Pin
honey the codewitch10-Jun-22 6:29
mvahoney the codewitch10-Jun-22 6:29 
AnswerRe: I'm feeling "diverse" today Pin
klinkenbecker10-Jun-22 7:40
klinkenbecker10-Jun-22 7:40 
GeneralRe: I'm feeling "diverse" today Pin
Daniel Pfeffer10-Jun-22 4:17
professionalDaniel Pfeffer10-Jun-22 4:17 
GeneralRe: I'm feeling "diverse" today Pin
Member 916705712-Jun-22 20:30
Member 916705712-Jun-22 20:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.