Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v15.4.0 proposal #36435

Merged
merged 95 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
095cef2
deps: update ICU to 68.1
targos Nov 20, 2020
cfc8ec1
src: fix label indentation
Trott Nov 21, 2020
03e8aaf
tools: bump cpplint.py to 1.5.2
Trott Nov 21, 2020
cfadd82
tools: refloat 7 Node.js patches to cpplint.py
Trott Oct 9, 2020
47397ff
src: update node.rc file description
devsnek Nov 20, 2020
186ad24
doc: cleanup events.md structure
jasnell Nov 12, 2020
dc19309
events: graduate Event, EventTarget, AbortController
jasnell Nov 3, 2020
fdf5d85
doc: add missing version to update cmd
ruyadorno Nov 20, 2020
44c4aad
doc: stabilize subpath patterns
guybedford Nov 19, 2020
c86c239
tools: update ESLint to 7.14.0
cjihrig Nov 21, 2020
be11976
tools: enable no-nonoctal-decimal-escape lint rule
cjihrig Nov 21, 2020
b176d61
doc: fix --experimental-wasm-modules text location
cjihrig Nov 21, 2020
44d6d0b
test: fix missed warning for non-experimental AbortController
jasnell Nov 23, 2020
69a8f05
test: improve test coverage SourceMap API
juanarbol Nov 11, 2020
39d0ced
process: refactor to use more primordials
aduh95 Nov 15, 2020
841e8f4
crypto: fix "Invalid JWK" error messages
panva Nov 20, 2020
617cb58
lib: refactor primordials.uncurryThis
aduh95 Nov 21, 2020
d29199e
quic: refactor to use more primordials
aduh95 Nov 15, 2020
03cf8db
doc: fix typo in events.md
lpinca Nov 22, 2020
66bc206
deps: V8: cherry-pick 86991d0587a1
bcoe Nov 25, 2020
65d89fd
doc: adding example to Buffer.isBuffer method
ntedgi Nov 23, 2020
2344e3e
benchmark : changed `fstat` to `fstatSync`
Narasimha1997 Nov 21, 2020
b613950
test: increase coverage for util.inspect()
Trott Nov 22, 2020
bcf7393
tools: bump cpplint to 1.5.3
Trott Nov 23, 2020
82c1e39
tools: refloat 7 Node.js patches to cpplint.py
Trott Oct 9, 2020
a2da7ba
tools: use using-declaration consistently
danbev Nov 24, 2020
2c7358e
test: fix flaky sequential/test-fs-watch
Trott Nov 24, 2020
e79bdc3
assert: refactor to use more primordials
aduh95 Nov 19, 2020
74adc44
build: fix typo in Makefile
RaisinTen Nov 19, 2020
a9ac86d
policy: refactor to use more primordials
aduh95 Nov 15, 2020
c04a2df
fs: refactor to use more primordials
aduh95 Nov 19, 2020
744b8aa
fs: pass ERR_DIR_CLOSED asynchronously to dir.close
Lxxyx Nov 24, 2020
3e5fcda
doc: add table header in intl.md
Trott Nov 25, 2020
5935ccc
tools: fix undeclared identifier FALSE
aduh95 Nov 25, 2020
6bc007f
tty: refactor to use more primordials
Lxxyx Nov 26, 2020
537e5cb
fs: move method definition from header
yashLadha Nov 25, 2020
b61ca1b
test: replace anonymous functions by arrows
arsenalzp Nov 14, 2020
d95ae65
tools: update highlight.js to 10.1.2
MylesBorins Nov 28, 2020
58abdca
http: enable call chaining with setHeader()
PoojaDurgad Nov 2, 2020
278862a
deps: upgrade npm to 7.0.15
ruyadorno Nov 27, 2020
d4de7c7
module: add isPreloading indicator
jasnell Nov 25, 2020
0401ffb
doc: add process for handling premature disclosure
mhdawson Nov 17, 2020
8cf1add
tools: update stability index linking logic
Trott Nov 26, 2020
6ebb98a
src: use ToLocal in DeserializeProperties
danbev Nov 26, 2020
ea09da4
test: fix typo in comment
inokawa Nov 29, 2020
2a24096
os: refactor to use more primordials
aduh95 Nov 20, 2020
fbd5652
v8: refactor to use more primordials
aduh95 Nov 20, 2020
ea46ca8
perf_hooks: refactor to use more primordials
aduh95 Nov 21, 2020
5f41f1b
http2: check write not scheduled in scope destructor
davedoesdev Nov 23, 2020
c14512b
errors: display original symbol name
bcoe Nov 8, 2020
802d44b
worker: add experimental BroadcastChannel
jasnell Nov 26, 2020
8d8d226
buffer: refactor to use more primordials
aduh95 Nov 18, 2020
4127eb2
https: add abortcontroller test
benjamingr Nov 28, 2020
29b5236
timers: reject with AbortError on cancellation
benjamingr Nov 29, 2020
f317bba
tls: permit null as a cipher value
Trott Nov 29, 2020
855a85c
events: support signal in EventTarget
benjamingr Nov 25, 2020
faca2b8
test: fix test-worker-broadcastchannel-wpt
Trott Dec 2, 2020
9cb53f6
repl: refactor to use more primordials
aduh95 Nov 16, 2020
b20409e
tls: refactor to use more primordials
aduh95 Nov 17, 2020
21c4704
worker: refactor to use more primordials
aduh95 Nov 16, 2020
0e7f0c6
path: refactor to use more primordials
aduh95 Nov 18, 2020
ca8db41
benchmark,child_process: remove failing benchmark parameter
aduh95 Nov 27, 2020
e7b2d91
src: use transferred consistently
danbev Dec 1, 2020
ab084c1
querystring: refactor to use more primordials
aduh95 Nov 18, 2020
4ca1bd8
child_process: refactor to use more primordials
Lxxyx Nov 25, 2020
a03aa0a
src: rename AliasedBufferInfo->AliasedBufferIndex
danbev Dec 1, 2020
8dadaa6
src: remove some duplication in DeserializeProps
danbev Dec 1, 2020
cc18907
module: refactor to use more primordials
aduh95 Nov 21, 2020
4b4caad
zlib: refactor to use more primordials
aduh95 Nov 20, 2020
22028aa
test: skip flaky parts of broadcastchannel test on Windows
Trott Dec 4, 2020
8d69d83
dgram: refactor to use more primordials
aduh95 Nov 19, 2020
b885409
readline: refactor to use more primordials
aduh95 Nov 15, 2020
2868ffb
tools: remove bashisms from release script
aduh95 Nov 14, 2020
754b7a7
tools: remove bashisms from macOS release scripts
aduh95 Nov 14, 2020
6033d30
stream: add FileHandle support to Read/WriteStream
mmomtchev Nov 2, 2020
8731a80
vm: add `SafeForTerminationScope`s for SIGINT interruptions
addaleax Dec 1, 2020
a8b95cf
tools: bump cpplint to 1.5.4
Trott Nov 30, 2020
e798770
tools: refloat 7 Node.js patches to cpplint.py
Trott Oct 9, 2020
224a647
child_process: add AbortSignal support
benjamingr Nov 28, 2020
2649c38
doc: add version metadata to timers/promises
cjihrig Dec 4, 2020
bef550a
doc: add Powershell oneliner to get Windows version
saitonakamura Nov 6, 2019
fbcb72a
test: increase coverage for readline
Lxxyx Dec 4, 2020
9db9be7
buffer: refactor to use primordials instead of Array#reduce
aduh95 Dec 4, 2020
1091a65
test: fix bootstrap test
benjamingr Dec 6, 2020
a7e794d
test: fix flaky test-http2-respond-file-error-pipe-offset
Trott Nov 28, 2020
b39d150
test: fix comment misspellings of transferred
Trott Dec 3, 2020
197ba21
stream: support abort signal
benjamingr Nov 9, 2020
f73a0a8
lib: fix typo in internal/errors.js
RaisinTen Dec 7, 2020
a15addc
string_decoder: refactor to use more primordials
aduh95 Nov 21, 2020
cedf51f
http2: refactor to use more primordials
aduh95 Nov 21, 2020
c2938bd
lib: add uncurried accessor properties to `primordials`
ExE-Boss Nov 30, 2020
47345a1
worker: refactor to use more primordials
aduh95 Dec 4, 2020
9ae59c8
tools: upgrade to @babel/eslint-parser 7.12.1
aduh95 Nov 29, 2020
8611b8f
net: refactor to use more primordials
aduh95 Nov 17, 2020
5e5927e
2020-12-09, Version 15.4.0 (Current)
danielleadams Dec 7, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
14 changes: 11 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const ModuleFindPath = Module._findPath;
const hacks = [
'eslint-plugin-node-core',
'eslint-plugin-markdown',
'babel-eslint',
'@babel/eslint-parser',
'@babel/plugin-syntax-class-properties',
];
Module._findPath = (request, paths, isMain) => {
const r = ModuleFindPath(request, paths, isMain);
Expand All @@ -37,8 +38,14 @@ Module._findPath = (request, paths, isMain) => {
module.exports = {
root: true,
plugins: ['markdown', 'node-core'],
parser: 'babel-eslint',
parserOptions: { sourceType: 'script' },
parser: '@babel/eslint-parser',
parserOptions: {
babelOptions: {
plugins: [Module._findPath('@babel/plugin-syntax-class-properties')],
},
requireConfigFile: false,
sourceType: 'script',
},
overrides: [
{
files: [
Expand Down Expand Up @@ -150,6 +157,7 @@ module.exports = {
'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 0, maxBOF: 0 }],
'no-new-require': 'error',
'no-new-symbol': 'error',
'no-nonoctal-decimal-escape': 'error',
'no-obj-calls': 'error',
'no-octal': 'error',
'no-path-concat': 'error',
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/1-bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repo. https://github.com/nodejs/help
Please fill in as much of the template below as you're able.

Version: output of `node -v`
Platform: output of `uname -a` (UNIX), or version and 32 or 64-bit (Windows)
Platform: output of `uname -a` (UNIX), or output of `"$([Environment]::OSVersion | ForEach-Object VersionString) $(if ([Environment]::Is64BitOperatingSystem) { "x64" } else { "x86" })"` in PowerShell console (Windows)
Subsystem: if known, please specify affected core module name
-->

Expand Down
6 changes: 3 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,9 @@ The externally maintained libraries used by Node.js are:
# Copyright (c) 2013 International Business Machines Corporation
# and others. All Rights Reserved.
#
# Project: http://code.google.com/p/lao-dictionary/
# Dictionary: http://lao-dictionary.googlecode.com/git/Lao-Dictionary.txt
# License: http://lao-dictionary.googlecode.com/git/Lao-Dictionary-LICENSE.txt
# Project: https://github.com/veer66/lao-dictionary
# Dictionary: https://github.com/veer66/lao-dictionary/blob/master/Lao-Dictionary.txt
# License: https://github.com/veer66/lao-dictionary/blob/master/Lao-Dictionary-LICENSE.txt
# (copied below)
#
# This file is derived from the above dictionary, with slight
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ $(PKG): release-only
--release-urlbase=$(RELEASE_URLBASE) \
$(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS)
$(MAKE) install V=$(V) DESTDIR=$(MACOSOUTDIR)/dist/node
SIGN="$(CODESIGN_CERT)" PKGDIR="$(MACOSOUTDIR)/dist/node/usr/local" bash \
SIGN="$(CODESIGN_CERT)" PKGDIR="$(MACOSOUTDIR)/dist/node/usr/local" sh \
tools/osx-codesign.sh
mkdir -p $(MACOSOUTDIR)/dist/npm/usr/local/lib/node_modules
mkdir -p $(MACOSOUTDIR)/pkgs
Expand All @@ -1001,8 +1001,8 @@ $(PKG): release-only
productbuild --distribution $(MACOSOUTDIR)/installer/productbuild/distribution.xml \
--resources $(MACOSOUTDIR)/installer/productbuild/Resources \
--package-path $(MACOSOUTDIR)/pkgs ./$(PKG)
SIGN="$(PRODUCTSIGN_CERT)" PKG="$(PKG)" bash tools/osx-productsign.sh
bash tools/osx-notarize.sh $(FULLVERSION)
SIGN="$(PRODUCTSIGN_CERT)" PKG="$(PKG)" sh tools/osx-productsign.sh
sh tools/osx-notarize.sh $(FULLVERSION)

.PHONY: pkg
# Builds the macOS installer for releases.
Expand Down Expand Up @@ -1120,7 +1120,7 @@ $(BINARYTAR): release-only
cp LICENSE $(BINARYNAME)
cp CHANGELOG.md $(BINARYNAME)
ifeq ($(OSTYPE),darwin)
SIGN="$(CODESIGN_CERT)" PKGDIR="$(BINARYNAME)" bash tools/osx-codesign.sh
SIGN="$(CODESIGN_CERT)" PKGDIR="$(BINARYNAME)" sh tools/osx-codesign.sh
endif
tar -cf $(BINARYNAME).tar $(BINARYNAME)
$(RM) -r $(BINARYNAME)
Expand Down Expand Up @@ -1346,7 +1346,7 @@ lint-py:
PYTHONPATH=tools/pip $(PYTHON) -m flake8 --count --show-source --statistics .
else
lint-py:
$(warning Python linting with flake8 is not avalible)
$(warning Python linting with flake8 is not available)
$(warning Run 'make lint-py-build')
endif

Expand Down
2 changes: 1 addition & 1 deletion benchmark/child_process/child-process-read-ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (process.argv[2] === 'child') {
const bench = common.createBenchmark(main, {
len: [
64, 256, 1024, 4096, 16384, 65536,
65536 << 4, 65536 << 8,
65536 << 4, 65536 << 6 - 1,
],
dur: [5]
});
Expand Down
2 changes: 1 addition & 1 deletion benchmark/fs/bench-statSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ function main({ n, statSyncType }) {
}
bench.end(n);

if (statSyncType === 'fstat')
if (statSyncType === 'fstatSync')
fs.closeSync(arg);
}
6 changes: 3 additions & 3 deletions deps/icu-small/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ property of their respective owners.
# Copyright (c) 2013 International Business Machines Corporation
# and others. All Rights Reserved.
#
# Project: http://code.google.com/p/lao-dictionary/
# Dictionary: http://lao-dictionary.googlecode.com/git/Lao-Dictionary.txt
# License: http://lao-dictionary.googlecode.com/git/Lao-Dictionary-LICENSE.txt
# Project: https://github.com/veer66/lao-dictionary
# Dictionary: https://github.com/veer66/lao-dictionary/blob/master/Lao-Dictionary.txt
# License: https://github.com/veer66/lao-dictionary/blob/master/Lao-Dictionary-LICENSE.txt
# (copied below)
#
# This file is derived from the above dictionary, with slight
Expand Down
4 changes: 2 additions & 2 deletions deps/icu-small/README-FULL-ICU.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ICU sources - auto generated by shrink-icu-src.py

This directory contains the ICU subset used by --with-intl=full-icu
It is a strict subset of ICU 67 source files with the following exception(s):
* deps/icu-small/source/data/in/icudt67l.dat.bz2 : compressed data file
It is a strict subset of ICU 68 source files with the following exception(s):
* deps/icu-small/source/data/in/icudt68l.dat.bz2 : compressed data file


To rebuild this directory, see ../../tools/icu/README.md
11 changes: 11 additions & 0 deletions deps/icu-small/source/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# © 2020 and later: Unicode, Inc. and others.
# License & terms of use: http://www.unicode.org/copyright.html

---
Language: Cpp
BasedOnStyle: LLVM
IndentWidth: 4
ColumnLimit: 105
AllowShortBlocksOnASingleLine: false
AllowShortIfStatementsOnASingleLine: true
...
2 changes: 1 addition & 1 deletion deps/icu-small/source/common/bmpset.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class BMPSet : public UMemory {
*/
UBool latin1Contains[0x100];

/* TRUE if contains(U+FFFD). */
/* true if contains(U+FFFD). */
UBool containsFFFD;

/*
Expand Down
4 changes: 2 additions & 2 deletions deps/icu-small/source/common/brkeng.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class LanguageBreakEngine : public UMemory {
* a particular kind of break.</p>
*
* @param c A character which begins a run that the engine might handle
* @return TRUE if this engine handles the particular character and break
* @return true if this engine handles the particular character and break
* type.
*/
virtual UBool handles(UChar32 c) const = 0;
Expand Down Expand Up @@ -171,7 +171,7 @@ class UnhandledEngine : public LanguageBreakEngine {
* a particular kind of break.</p>
*
* @param c A character which begins a run that the engine might handle
* @return TRUE if this engine handles the particular character and break
* @return true if this engine handles the particular character and break
* type.
*/
virtual UBool handles(UChar32 c) const;
Expand Down
4 changes: 2 additions & 2 deletions deps/icu-small/source/common/bytesinkutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class U_COMMON_API ByteSinkUtil {
static UBool appendUnchanged(const uint8_t *s, int32_t length,
ByteSink &sink, uint32_t options, Edits *edits,
UErrorCode &errorCode) {
if (U_FAILURE(errorCode)) { return FALSE; }
if (U_FAILURE(errorCode)) { return false; }
if (length > 0) { appendNonEmptyUnchanged(s, length, sink, options, edits); }
return TRUE;
return true;
}

static UBool appendUnchanged(const uint8_t *s, const uint8_t *limit,
Expand Down
28 changes: 26 additions & 2 deletions deps/icu-small/source/common/charstr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "cmemory.h"
#include "cstring.h"
#include "uinvchar.h"
#include "ustr_imp.h"

U_NAMESPACE_BEGIN

Expand All @@ -46,6 +47,19 @@ char *CharString::cloneData(UErrorCode &errorCode) const {
return p;
}

int32_t CharString::extract(char *dest, int32_t capacity, UErrorCode &errorCode) const {
if (U_FAILURE(errorCode)) { return len; }
if (capacity < 0 || (capacity > 0 && dest == nullptr)) {
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
return len;
}
const char *src = buffer.getAlias();
if (0 < len && len <= capacity && src != dest) {
uprv_memcpy(dest, src, len);
}
return u_terminateChars(dest, capacity, len, &errorCode);
}

CharString &CharString::copyFrom(const CharString &s, UErrorCode &errorCode) {
if(U_SUCCESS(errorCode) && this!=&s && ensureCapacity(s.len+1, 0, errorCode)) {
len=s.len;
Expand Down Expand Up @@ -197,7 +211,7 @@ CharString &CharString::appendPathPart(StringPiece s, UErrorCode &errorCode) {
}
char c;
if(len>0 && (c=buffer[len-1])!=U_FILE_SEP_CHAR && c!=U_FILE_ALT_SEP_CHAR) {
append(U_FILE_SEP_CHAR, errorCode);
append(getDirSepChar(), errorCode);
}
append(s, errorCode);
return *this;
Expand All @@ -207,9 +221,19 @@ CharString &CharString::ensureEndsWithFileSeparator(UErrorCode &errorCode) {
char c;
if(U_SUCCESS(errorCode) && len>0 &&
(c=buffer[len-1])!=U_FILE_SEP_CHAR && c!=U_FILE_ALT_SEP_CHAR) {
append(U_FILE_SEP_CHAR, errorCode);
append(getDirSepChar(), errorCode);
}
return *this;
}

char CharString::getDirSepChar() const {
char dirSepChar = U_FILE_SEP_CHAR;
#if (U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR)
// We may need to return a different directory separator when building for Cygwin or MSYS2.
if(len>0 && !uprv_strchr(data(), U_FILE_SEP_CHAR) && uprv_strchr(data(), U_FILE_ALT_SEP_CHAR))
dirSepChar = U_FILE_ALT_SEP_CHAR;
#endif
return dirSepChar;
}

U_NAMESPACE_END
26 changes: 24 additions & 2 deletions deps/icu-small/source/common/charstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ class U_COMMON_API CharString : public UMemory {
* The caller must uprv_free() the result.
*/
char *cloneData(UErrorCode &errorCode) const;
/**
* Copies the contents of the string into dest.
* Checks if there is enough space in dest, extracts the entire string if possible,
* and NUL-terminates dest if possible.
*
* If the string fits into dest but cannot be NUL-terminated (length()==capacity),
* then the error code is set to U_STRING_NOT_TERMINATED_WARNING.
* If the string itself does not fit into dest (length()>capacity),
* then the error code is set to U_BUFFER_OVERFLOW_ERROR.
*
* @param dest Destination string buffer.
* @param capacity Size of the dest buffer (number of chars).
* @param errorCode ICU error code.
* @return length()
*/
int32_t extract(char *dest, int32_t capacity, UErrorCode &errorCode) const;

bool operator==(StringPiece other) const {
return len == other.length() && (len == 0 || uprv_memcmp(data(), other.data(), len) == 0);
Expand Down Expand Up @@ -141,13 +157,13 @@ class U_COMMON_API CharString : public UMemory {

/**
* Appends a filename/path part, e.g., a directory name.
* First appends a U_FILE_SEP_CHAR if necessary.
* First appends a U_FILE_SEP_CHAR or U_FILE_ALT_SEP_CHAR if necessary.
* Does nothing if s is empty.
*/
CharString &appendPathPart(StringPiece s, UErrorCode &errorCode);

/**
* Appends a U_FILE_SEP_CHAR if this string is not empty
* Appends a U_FILE_SEP_CHAR or U_FILE_ALT_SEP_CHAR if this string is not empty
* and does not already end with a U_FILE_SEP_CHAR or U_FILE_ALT_SEP_CHAR.
*/
CharString &ensureEndsWithFileSeparator(UErrorCode &errorCode);
Expand All @@ -160,6 +176,12 @@ class U_COMMON_API CharString : public UMemory {

CharString(const CharString &other); // forbid copying of this class
CharString &operator=(const CharString &other); // forbid copying of this class

/**
* Returns U_FILE_ALT_SEP_CHAR if found in string, and U_FILE_SEP_CHAR is not found.
* Otherwise returns U_FILE_SEP_CHAR.
*/
char getDirSepChar() const;
};

U_NAMESPACE_END
Expand Down
55 changes: 55 additions & 0 deletions deps/icu-small/source/common/charstrmap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// © 2020 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html

// charstrmap.h
// created: 2020sep01 Frank Yung-Fong Tang

#ifndef __CHARSTRMAP_H__
#define __CHARSTRMAP_H__

#include <utility>
#include "unicode/utypes.h"
#include "unicode/uobject.h"
#include "uhash.h"

U_NAMESPACE_BEGIN

/**
* Map of const char * keys & values.
* Stores pointers as is: Does not own/copy/adopt/release strings.
*/
class CharStringMap final : public UMemory {
public:
/** Constructs an unusable non-map. */
CharStringMap() : map(nullptr) {}
CharStringMap(int32_t size, UErrorCode &errorCode) {
map = uhash_openSize(uhash_hashChars, uhash_compareChars, uhash_compareChars,
size, &errorCode);
}
CharStringMap(CharStringMap &&other) U_NOEXCEPT : map(other.map) {
other.map = nullptr;
}
CharStringMap(const CharStringMap &other) = delete;
~CharStringMap() {
uhash_close(map);
}

CharStringMap &operator=(CharStringMap &&other) U_NOEXCEPT {
map = other.map;
other.map = nullptr;
return *this;
}
CharStringMap &operator=(const CharStringMap &other) = delete;

const char *get(const char *key) const { return static_cast<const char *>(uhash_get(map, key)); }
void put(const char *key, const char *value, UErrorCode &errorCode) {
uhash_put(map, const_cast<char *>(key), const_cast<char *>(value), &errorCode);
}

private:
UHashtable *map;
};

U_NAMESPACE_END

#endif // __CHARSTRMAP_H__
Loading