mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-29 18:47:31 +09:00
Issue #2046 - Move ScopedICUObject into builtin/intl/ScopedICUObject.h
This commit is contained in:
parent
cdda874cff
commit
0172619642
2 changed files with 45 additions and 26 deletions
|
|
@ -22,6 +22,7 @@
|
||||||
#include "jscntxt.h"
|
#include "jscntxt.h"
|
||||||
#include "jsobj.h"
|
#include "jsobj.h"
|
||||||
|
|
||||||
|
#include "builtin/intl/ScopedICUObject.h"
|
||||||
#include "builtin/IntlTimeZoneData.h"
|
#include "builtin/IntlTimeZoneData.h"
|
||||||
#include "ds/Sort.h"
|
#include "ds/Sort.h"
|
||||||
#include "unicode/plurrule.h"
|
#include "unicode/plurrule.h"
|
||||||
|
|
@ -183,32 +184,6 @@ icuLocale(const char* locale)
|
||||||
return locale;
|
return locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simple RAII for ICU objects. Unfortunately, ICU's C++ API is uniformly
|
|
||||||
// unstable, so we can't use its smart pointers for this.
|
|
||||||
template <typename T, void (Delete)(T*)>
|
|
||||||
class ScopedICUObject
|
|
||||||
{
|
|
||||||
T* ptr_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit ScopedICUObject(T* ptr)
|
|
||||||
: ptr_(ptr)
|
|
||||||
{}
|
|
||||||
|
|
||||||
~ScopedICUObject() {
|
|
||||||
if (ptr_)
|
|
||||||
Delete(ptr_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// In cases where an object should be deleted on abnormal exits,
|
|
||||||
// but returned to the caller if everything goes well, call forget()
|
|
||||||
// to transfer the object just before returning.
|
|
||||||
T* forget() {
|
|
||||||
T* tmp = ptr_;
|
|
||||||
ptr_ = nullptr;
|
|
||||||
return tmp;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// The inline capacity we use for the char16_t Vectors.
|
// The inline capacity we use for the char16_t Vectors.
|
||||||
static const size_t INITIAL_CHAR_BUFFER_SIZE = 32;
|
static const size_t INITIAL_CHAR_BUFFER_SIZE = 32;
|
||||||
|
|
|
||||||
44
js/src/builtin/intl/ScopedICUObject.h
Normal file
44
js/src/builtin/intl/ScopedICUObject.h
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#ifndef builtin_intl_ScopedICUObject_h
|
||||||
|
#define builtin_intl_ScopedICUObject_h
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A simple RAII class to assure ICU objects are automatically deallocated at
|
||||||
|
* scope end. Unfortunately, ICU's C++ API is uniformly unstable, so we can't
|
||||||
|
* use its smart pointers for this.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace js {
|
||||||
|
|
||||||
|
template <typename T, void (Delete)(T*)>
|
||||||
|
class ScopedICUObject
|
||||||
|
{
|
||||||
|
T* ptr_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ScopedICUObject(T* ptr)
|
||||||
|
: ptr_(ptr)
|
||||||
|
{}
|
||||||
|
|
||||||
|
~ScopedICUObject() {
|
||||||
|
if (ptr_)
|
||||||
|
Delete(ptr_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// In cases where an object should be deleted on abnormal exits,
|
||||||
|
// but returned to the caller if everything goes well, call forget()
|
||||||
|
// to transfer the object just before returning.
|
||||||
|
T* forget() {
|
||||||
|
T* tmp = ptr_;
|
||||||
|
ptr_ = nullptr;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace js
|
||||||
|
|
||||||
|
#endif /* builtin_intl_ScopedICUObject_h */
|
||||||
Loading…
Add table
Add a link
Reference in a new issue