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: introduce InlineDecoder · easternbloc/node@aca2011

File tree

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

‎src/string_bytes.h‎

Copy file name to clipboardExpand all lines: src/string_bytes.h
+47Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,60 @@
55

66
#include "v8.h"
77
#include "node.h"
8+
#include "env.h"
9+
#include "env-inl.h"
810

911
namespace node {
1012

1113
extern int WRITE_UTF8_FLAGS;
1214

1315
class StringBytes {
1416
public:
17+
class InlineDecoder {
18+
public:
19+
InlineDecoder() : out_(nullptr) {
20+
}
21+
22+
~InlineDecoder() {
23+
if (out_ != out_st_)
24+
delete[] out_;
25+
out_ = nullptr;
26+
}
27+
28+
inline bool Decode(Environment* env,
29+
v8::Handle<v8::String> string,
30+
v8::Handle<v8::Value> encoding,
31+
enum encoding _default) {
32+
enum encoding enc = ParseEncoding(env->isolate(), encoding, _default);
33+
if (!StringBytes::IsValidString(env->isolate(), string, enc)) {
34+
env->ThrowTypeError("Bad input string");
35+
return false;
36+
}
37+
38+
size_t buflen = StringBytes::StorageSize(env->isolate(), string, enc);
39+
if (buflen > sizeof(out_st_))
40+
out_ = new char[buflen];
41+
else
42+
out_ = out_st_;
43+
size_ = StringBytes::Write(env->isolate(),
44+
out_,
45+
buflen,
46+
string,
47+
enc);
48+
return true;
49+
}
50+
51+
inline const char* out() const { return out_; }
52+
inline size_t size() const { return size_; }
53+
54+
private:
55+
static const int kStorageSize = 1024;
56+
57+
char out_st_[kStorageSize];
58+
char* out_;
59+
size_t size_;
60+
};
61+
1562
// Does the string match the encoding? Quick but non-exhaustive.
1663
// Example: a HEX string must have a length that's a multiple of two.
1764
// FIXME(bnoordhuis) IsMaybeValidString()? Naming things is hard...

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.