New answers tagged

1

All the functionality is written in one fat function, which prevents modularization of code. Try to break up it into subfunctions; you could separate: std::string word; while (++idx < length) { ch = tclString[idx]; if (ch == ' ' || ch == '}') break; word += ch; } This is simply trying to tokenize the ...


0

After suggestions from @AJNeufeld and @FMc, It helped me a lot to understand and make changes in the code to increase the readability. The code looks more pythonic now, I would say. Here's the final code: from typing import List, Optional from dataclasses import dataclass, field import re TABLE_HEADER = '# val err- err+ xmin xmax' @dataclass(...


1

You already have one useful code review, so I'll focus less on those details and more on parsing strategy and your question about organizing the parsing into smaller, more-focused functions. When building a parser, don't forget error reporting. It's tempting when building a parser to sanitize the input as early as possible, for example by stripping lines or ...


3

Global Constants block_names = ("object", "region", "info", "table ") keywords = ("define", "select", "reject", "take", "using", "sort", "weight", "histo") table_k_v = "# val err- err+ xmin xmax" These should be ...


3

Any better ideas? Consume the buffer Rather than leave the buffer "as-is" while parsing, adjust its start and end while parsing. char *s = httpHeader; s = parse(s, "Content-Length", "\n"); if (s == NULL) Handle_Error(); s = parse(s, ":", "\r"); if (s == NULL) Handle_Error(); long contentLenVal = strtol(s, .....


4

I mean to say this in the gentlest possible way, but from top to bottom this is a bad idea. It would take a more detailed explanation of why this creature exists to convince me otherwise. Your default callback produces some pretty crazy results: ^ and 1 both evaluate to False, for instance. A critical step in security is to limit DOS potential by ...


2

Parsing your file is effectively meaningless unless you give us some constraints, background information, context and realistic scenarios. I'm going to make some sweeping assumptions and show you one way to parse the data that's moderately advanced, but first, on your existing code: It's not only all in one class, it's all in one function (that you don't ...


4

Clippy First, always, always run cargo clippy. Clippy gives you lots of helpful tips to make your code more idiomatic and simpler, and sometimes catches more serious missteps. From Clippy: Lots of unnecessary return statements. To return a value on the last line of a function (or the last line of each if branch), in Rust it is preferred to omit the return ...


2

Your code had a compiler error and was missing some context. I used the following input as random.txt.' string1 string2 B|C|D R|S|T 100 200 300 400 1 2 3 4 H|A B|C|D R|S|T 200 300 400 500 2 3 4 5 H|A After fixing your code and running it, I generated the following output. string1 string2 B|C|D R|S|T 100 1 H|A B|C|D R|S|T 200 2 H|A You're missing some ...


Top 50 recent answers are included