Skip to main content
10 votes

is_decimal Function Implementation in C++

Tear down the state machine Your use of a state machine is not a bad idea, per se, as a model, but it can be simplified in code. (If you do insist on using a state machine, then name the states) Look ...
Matthieu M.'s user avatar
  • 5,257
9 votes
Accepted

Convert string name to uppercase

Avoid unhelpful comments: #include <ctype.h> // toupper #include <string.h> // NULL NULL from ...
Harith's user avatar
  • 8,846
8 votes
Accepted

C++ program to format byte sequences into Python like string representations

We're missing an include of <cstring> (required for std::memcpy). Most C++ programmers prefer ...
Toby Speight's user avatar
  • 76.9k
7 votes

Implementing strscpy(): Is using errno as a negative return value a bad practice?

Use C99's new meaning of static keyword: If we shift around the parameters, we can have: ...
Harith's user avatar
  • 8,846
7 votes
Accepted

locale-aware trim functions for std::string

It's surprising that std::string defaults to "C" locale, but all other string types default to using the global locale. That's likely to cause user ...
Toby Speight's user avatar
  • 76.9k
7 votes

Convert string name to uppercase

There are currently four VG answers. Without simply rephrasing or plagiarising that content, I've nothing else to add to their commentary about the OP's code. However, there is one more suggestion ...
Fe2O3's user avatar
  • 951
7 votes

Convert string name to uppercase

converts a string in the format "this-string" to "This String" I'd take this to mean each subset of letters should begin with an uppercase letter. The ...
chux - Reinstate Monica's user avatar
6 votes

Convert string name to uppercase

If you're willing to link against a regex library there's simpler ways to accomplish this. Let's stick with just ISO C for now. specification We helpfully see "converts a string in the format &...
J_H's user avatar
  • 29.1k
6 votes

Convert string name to uppercase

The functions in ctype.h expect input in the range of unsigned char, so you should cast char ...
ad absurdum's user avatar
6 votes

Convert string name to uppercase

A nice classic C program. Other than the other various notions on fixing the tests for a letter to be upper-cased, I have two issues: Header For a function in an external compilation unit, there ...
David G.'s user avatar
  • 1,426
6 votes
Accepted

is_decimal Function Implementation in C++

Tests Thanks for writing a test suite. This code is well suited to automated testing, and the start you've made here is appreciated. Since the function we're testing is ...
Toby Speight's user avatar
  • 76.9k
5 votes

is_decimal Function Implementation in C++

Avoid redundant trips down the string is_decimal() could be used a lot and deserves some improvements. ...
chux - Reinstate Monica's user avatar
5 votes

locale-aware trim functions for std::string

Make it more generic Nothing in your code actually depends on str being a std::string. It would work on any container that has ...
G. Sliepen's user avatar
  • 58.3k
5 votes

Convert string name to uppercase

Title-Case of Hyphenated Words This algorithm only recognizes the space character as a word separator. It doesn’t capitalize words after hyphens, unlike Standard English. Unicode If you’re formatting ...
Davislor's user avatar
  • 7,956
5 votes
Accepted

Implementing basename, stpcpy, asprintf, vasprintf, strchrnul, and strcasecmp

bump the pointer ...
J_H's user avatar
  • 29.1k
4 votes

Implementing strscpy(): Is using errno as a negative return value a bad practice?

Opinion: argument order ssize_t ft_strscpy(char *dst, const char *src, size_t size), even though it matches sized_strscpy(), ...
3 votes

Convert string name to uppercase

Yes, I think it is possible to make it simpler. Firstly, here is the code: ...
c19's user avatar
  • 114
3 votes
Accepted

Implementing strscpy(): Is using errno as a negative return value a bad practice?

Your implementation is correct. I dislike the use of a negative return value in this situation. What is the problem that the function is trying to fix? I think that a large part of the problem is ...
c19's user avatar
  • 114
3 votes

Implementing basename, stpcpy, asprintf, vasprintf, strchrnul, and strcasecmp

Bug: questionable compare. Code does if (islower((unsigned char) p)) { p = toupper((unsigned char) p); } yet documentation has In the ...
chux - Reinstate Monica's user avatar
3 votes

Implementing basename, stpcpy, asprintf, vasprintf, strchrnul, and strcasecmp

Potential idea C2x is planned to support QChar *strchr(QChar *s, int c); This QChar allows one to call ...
2 votes

locale-aware trim functions for std::string

Based on the suggestions, I came up with the following solution that satisfies my needs and is not too complicated: ...
digito_evo's user avatar
2 votes

Implementing basename, stpcpy, asprintf, vasprintf, strchrnul, and strcasecmp

Whilst util_stpcpy() isn't wrong, it's possibly less efficient than a implementation tuned for the target architecture, which can fold finding the end into an ...
Toby Speight's user avatar
  • 76.9k
1 vote

Optimize for compute/timespace - substring matching STD pk / sk format

If your grants list is sorted, you can run through it, deleting those that has the previous node as a prefix. That would require a linear number of comparisons. Of course sorting is O(n log n) string ...
Peer Sommerlund's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible