cast icon indicating copy to clipboard operation
cast copied to clipboard

Added ToBase<Int|Uint|etc>() functions for ToBaseInt('08', 10) => 8 (Fixes #232)

Open andreimerlescu opened this issue 8 months ago • 3 comments

This PR fixes #232 by allowing the user to cast as a Base derived value from the interface.

Methods added:

# Public Methods inside `cast.go`
ToBaseInt64(input interface, base int)
ToBaseInt32(input interface, base int)
ToBaseInt16(input interface, base int)
ToBaseInt8(input interface, base int)
ToBaseInt(input interface, base int)
ToBaseUint(input interface, base int)
ToBaseUint64(input interface, base int)
ToBaseUint32(input interface, base int)
ToBaseUint16(input interface, base int)
ToBaseUint8(input interface, base int)

# Internal Methods inside `caste.go`
ToUint8EB(input interface, base int)
ToUint16EB(input interface, base int)
ToUint32EB(input interface, base int)
ToUint64EB(input interface, base int)
ToUintEB(input interface, base int)
ToIntEB(input interface, base int)
ToInt8EB(input interface, base int)
ToInt16EB(input interface, base int)
ToInt32EB(input interface, base int)
ToInt64EB(input interface, base int)

Quite literally, this PR duplicates a TON of code (lovely) and provides you the ability to specify the 2nd argument on the strconv.Parse<Int|Uint>(num, base, bits) functions in caste.go.

andreimerlescu avatar May 29 '25 12:05 andreimerlescu

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar May 29 '25 12:05 CLAassistant

Thanks @andreimerlescu !

Let me see if we can reduce the code duplication.

Question: Why don't ToXYZEB functions follow the ToBaseXYZ pattern (ToBaseXYZE)?

sagikazarmark avatar May 29 '25 12:05 sagikazarmark

#250 might help reducing the amount of code duplications.

sagikazarmark avatar May 29 '25 14:05 sagikazarmark