Comments (2)
Hey zammbi, please update to latest source and test following implementation before merging:
#include "sole.hpp"
bool is_valid( const char *str ) {
/*
unsigned samples[] = {
sizeof("oCRsAqD-BMfTOs8VvjA"), // [19]
sizeof("QN2LEuUg-B7DNx1YIcnz"), // [20]
sizeof("oTDTokEuR-Dm8Lm3zjiQu"), // [21]
sizeof("Bh3tngmuiH-BfzbduiSRvT"), // [22]
sizeof("G2anmplueET-Bpr24ZCKSlg"), // [23]
sizeof("1581b866-2257-496c-b1b2-3a855b8a32e8") // [36]
};
*/
int len = strlen(str);
int maybe = 0;
if( len == 36 ) {
maybe = ( str[8] == '-' && str[13] == '-' && str[18] == '-' && str[23] == '-' ) &&
( str[14] == '4' || str[14] == '1' || str[14] == '0' );
}
else
if( len >= 19 && len <= 23 ) {
maybe = str[len - 12] == '-';
}
if( maybe ) {
sole::uuid x = sole::rebuild(str);
return x.ab && x.cd;
}
return false;
}
#include <assert.h>
int main() {
assert(!is_valid("hello world") );
assert( is_valid("oCRsAqD-BMfTOs8VvjA")); // [19]
assert( is_valid("QN2LEuUg-B7DNx1YIcnz")); // [20]
assert( is_valid("oTDTokEuR-Dm8Lm3zjiQu")); // [21]
assert( is_valid("Bh3tngmuiH-BfzbduiSRvT")); // [22]
assert( is_valid("G2anmplueET-Bpr24ZCKSlg")); // [23]
assert( is_valid("1581b866-2257-496c-b1b2-3a855b8a32e8")); // [36]
assert(!is_valid("158lb866-2257-496c-b1b2-3a855b8a32e8")); // [36]
assert(!is_valid("1581b866-2257-596c-b1b2-3a855b8a32e8")); // [36]
assert(!is_valid("1581b866-2257-496c-b1b2-3a855b8a32e8 ")); // [36]
}
If that's good enough then I'll commit it (properly) anytime soon :)
ty
from sole.
Thanks for a quick solution.
However since all my guids should be valid, this method would run slower than just doing the sole::rebuild check. I don't want any object creation. Just to check if it's a valid guid string if possible. I'm trying to optimise a hot spot piece of code :)
from sole.
Related Issues (20)
- Support forward declaration HOT 3
- Build fails when building on GCC mac. HOT 2
- clang warning on exit-time declaration HOT 17
- Better performance for uuid4 HOT 4
- msys2 compile warinig HOT 1
- uuid4 does not seem to be thread safe.
- uuid4 seems unsafe base on C++ standards HOT 1
- Compile error in C++17 HOT 6
- Warning: possible misuse of comma operator here HOT 1
- need support for android platform HOT 1
- Tag a release HOT 1
- Tag release v1.0.2 HOT 2
- error: call to 'clock_gettime' is ambiguous HOT 4
- socket leak HOT 1
- Call to member function "transform" is ambiguous HOT 5
- time to create a new release?
- error: type of thread-local variable has non-trivial destruction HOT 5
- -Wunused-value compiler warning HOT 2
- Github url in the comments HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sole.