From 3ef61c73a97b31000a21e323e04ad5397e517c4c Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 6 Sep 2017 09:37:59 -0400 Subject: 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 Reviewed-by: Tom Sepez --- xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'xfa/fxfa/fm2js') 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(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 argOne = GetSimpleValue(pThis, args, 0); iNum = static_cast(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 -- cgit v1.2.3