add morkEnv::HexToByte()

This commit is contained in:
davidmc%netscape.com 1999-04-19 22:15:35 +00:00
parent 40afc35456
commit ad28c79bd4
2 changed files with 58 additions and 0 deletions

View File

@ -28,6 +28,10 @@
#include "morkNode.h"
#endif
#ifndef _MORKCH_
#include "morkCh.h"
#endif
#ifndef _MORKENV_
#include "morkEnv.h"
#endif
@ -182,6 +186,31 @@ morkEnv::OidAsHex(void* outBuf, const mdbOid& inOid)
return idSize + scopeSize + 2;
}
mork_u1
morkEnv::HexToByte(mork_ch inFirstHex, mork_ch inSecondHex)
{
mork_u1 hi = 0; // high four hex bits
mork_flags f = morkCh_GetFlags(inFirstHex);
if ( morkFlags_IsDigit(f) )
hi = inFirstHex - '0';
else if ( morkFlags_IsUpper(f) )
hi = (inFirstHex - 'A') + 10;
else if ( morkFlags_IsLower(f) )
hi = (inFirstHex - 'a') + 10;
mork_u1 lo = 0; // low four hex bits
f = morkCh_GetFlags(inSecondHex);
if ( morkFlags_IsDigit(f) )
lo = inSecondHex - '0';
else if ( morkFlags_IsUpper(f) )
lo = (inSecondHex - 'A') + 10;
else if ( morkFlags_IsLower(f) )
lo = (inSecondHex - 'a') + 10;
return (mork_u1) ((hi << 4) | lo);
}
mork_size
morkEnv::TokenAsHex(void* outBuf, mork_token inToken)
// TokenAsHex() is the same as sprintf(outBuf, "%lX", (long) inToken);

View File

@ -28,6 +28,10 @@
#include "morkNode.h"
#endif
#ifndef _MORKCH_
#include "morkCh.h"
#endif
#ifndef _MORKENV_
#include "morkEnv.h"
#endif
@ -182,6 +186,31 @@ morkEnv::OidAsHex(void* outBuf, const mdbOid& inOid)
return idSize + scopeSize + 2;
}
mork_u1
morkEnv::HexToByte(mork_ch inFirstHex, mork_ch inSecondHex)
{
mork_u1 hi = 0; // high four hex bits
mork_flags f = morkCh_GetFlags(inFirstHex);
if ( morkFlags_IsDigit(f) )
hi = inFirstHex - '0';
else if ( morkFlags_IsUpper(f) )
hi = (inFirstHex - 'A') + 10;
else if ( morkFlags_IsLower(f) )
hi = (inFirstHex - 'a') + 10;
mork_u1 lo = 0; // low four hex bits
f = morkCh_GetFlags(inSecondHex);
if ( morkFlags_IsDigit(f) )
lo = inSecondHex - '0';
else if ( morkFlags_IsUpper(f) )
lo = (inSecondHex - 'A') + 10;
else if ( morkFlags_IsLower(f) )
lo = (inSecondHex - 'a') + 10;
return (mork_u1) ((hi << 4) | lo);
}
mork_size
morkEnv::TokenAsHex(void* outBuf, mork_token inToken)
// TokenAsHex() is the same as sprintf(outBuf, "%lX", (long) inToken);