summaryrefslogtreecommitdiff
path: root/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-09-06 09:37:59 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-09-06 13:47:18 +0000
commit3ef61c73a97b31000a21e323e04ad5397e517c4c (patch)
tree516534f41936adbf4eb2f1ba447508847ef98dac /xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
parent555b31faa192c7a85c84979bea28d4914e93c784 (diff)
downloadpdfium-3ef61c73a97b31000a21e323e04ad5397e517c4c.tar.xz
GUID cleanup
This CL removes fx_guid and inlines into CXFA_FM2JSContext as needed. Change-Id: I08a1f03fd4be46730eee24ab73b8b5c0daf9cd7d Reviewed-on: https://pdfium-review.googlesource.com/13094 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp')
-rw-r--r--xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
index 6c70a3db1a..f49d98ab61 100644
--- a/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
@@ -14,7 +14,7 @@
#include "core/fxcrt/cfx_decimal.h"
#include "core/fxcrt/cfx_widetextbuf.h"
#include "core/fxcrt/fx_extension.h"
-#include "core/fxcrt/fx_guid.h"
+#include "core/fxcrt/fx_random.h"
#include "fxjs/cfxjse_arguments.h"
#include "fxjs/cfxjse_class.h"
#include "fxjs/cfxjse_value.h"
@@ -514,6 +514,23 @@ bool IsPartOfNumberW(wchar_t ch) {
return std::iswdigit(ch) || ch == L'-' || ch == L'.';
}
+CFX_ByteString GUIDString(bool bSeparator) {
+ uint8_t data[16];
+ FX_Random_GenerateMT(reinterpret_cast<uint32_t*>(data), 4);
+ data[6] = (data[6] & 0x0F) | 0x40;
+
+ CFX_ByteString bsStr;
+ char* pBuf = bsStr.GetBuffer(40);
+ for (int32_t i = 0; i < 16; ++i, pBuf += 2) {
+ if (bSeparator && (i == 4 || i == 6 || i == 8 || i == 10))
+ *pBuf++ = L'-';
+
+ FXSYS_IntToTwoHexChars(data[i], pBuf);
+ }
+ bsStr.ReleaseBuffer(bSeparator ? 36 : 32);
+ return bsStr;
+}
+
} // namespace
// static
@@ -4324,11 +4341,7 @@ void CXFA_FM2JSContext::Uuid(CFXJSE_Value* pThis,
std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
iNum = static_cast<int32_t>(ValueToFloat(pThis, argOne.get()));
}
- FX_GUID guid;
- FX_GUID_CreateV4(&guid);
-
- CFX_ByteString bsUId = FX_GUID_ToString(&guid, !!iNum);
- args.GetReturnValue()->SetString(bsUId.AsStringC());
+ args.GetReturnValue()->SetString(GUIDString(!!iNum).AsStringC());
}
// static