1// Copyright 2014 PDFium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7#ifndef _FX_ALGORITHM 8#define _FX_ALGORITHM 9#define FX_IsOdd(a) ((a)&1) 10#ifdef __cplusplus 11extern "C" { 12#endif 13int32_t FX_Base64EncodeA(const uint8_t* pSrc, int32_t iSrcLen, FX_CHAR* pDst); 14int32_t FX_Base64DecodeA(const FX_CHAR* pSrc, int32_t iSrcLen, uint8_t* pDst); 15int32_t FX_Base64DecodeW(const FX_WCHAR* pSrc, int32_t iSrcLen, uint8_t* pDst); 16uint8_t FX_Hex2Dec(uint8_t hexHigh, uint8_t hexLow); 17int32_t FX_SeparateStringW(const FX_WCHAR* pStr, 18 int32_t iStrLen, 19 FX_WCHAR delimiter, 20 CFX_WideStringArray& pieces); 21#ifdef __cplusplus 22}; 23#endif 24template <class baseType> 25class CFX_DSPATemplate { 26 public: 27 int32_t Lookup(const baseType& find, const baseType* pArray, int32_t iCount) { 28 FXSYS_assert(pArray != NULL); 29 if (iCount < 1) { 30 return -1; 31 } 32 int32_t iStart = 0, iEnd = iCount - 1, iMid; 33 do { 34 iMid = (iStart + iEnd) / 2; 35 const baseType& v = pArray[iMid]; 36 if (find == v) { 37 return iMid; 38 } else if (find < v) { 39 iEnd = iMid - 1; 40 } else { 41 iStart = iMid + 1; 42 } 43 } while (iStart <= iEnd); 44 return -1; 45 } 46}; 47#endif 48