GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — string_bytes: add StringBytes::IsValidString() · littledan/node@dce26cc

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • string_bytes.cc
    • string_bytes.h
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/string_bytes.cc‎

Copy file name to clipboardExpand all lines: src/string_bytes.cc
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,13 @@ size_t StringBytes::Write(char* buf,
257257
}
258258

259259

260+
bool StringBytes::IsValidString(Handle<String> string, enum encoding enc) {
261+
if (enc == HEX && string->Length() % 2 != 0) return false;
262+
// TODO(bnoordhuis) Add BASE64 check?
263+
return true;
264+
}
265+
266+
260267
// Quick and dirty size calculation
261268
// Will always be at least big enough, but may have some extra
262269
// UTF8 can be as much as 3x the size, Base64 can have 1-2 extra bytes
Collapse file

‎src/string_bytes.h‎

Copy file name to clipboardExpand all lines: src/string_bytes.h
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ using v8::Value;
3636

3737
class StringBytes {
3838
public:
39+
// Does the string match the encoding? Quick but non-exhaustive.
40+
// Example: a HEX string must have a length that's a multiple of two.
41+
// FIXME(bnoordhuis) IsMaybeValidString()? Naming things is hard...
42+
static bool IsValidString(Handle<String> string, enum encoding enc);
43+
3944
// Fast, but can be 2 bytes oversized for Base64, and
4045
// as much as triple UTF-8 strings <= 65536 chars in length
4146
static size_t StorageSize(Handle<Value> val, enum encoding enc);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.