Skip to content

Commit

Permalink
Make conv functions nothrow and some nogc
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaTheFoxgirl committed Jul 22, 2024
1 parent e615e64 commit 0cbecd3
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions source/numem/conv.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,48 @@ version(NoC) {
import std.traits;
import numem.mem.exception;

@nogc:

/**
Convert nstring to signed integer
*/
T toInt(T)(nstring str) if (isSigned!T && isIntegral!T) {
T toInt(T)(nstring str) nothrow if (isSigned!T && isIntegral!T) {
return cast(T)atol(str.toCString());
}

/**
Convert string slice to signed integer
*/
T toInt(T)(string str) if (isSigned!T && isIntegral!T) {
T toInt(T)(string str) nothrow if (isSigned!T && isIntegral!T) {
return cast(T)strtol(str.ptr, str.ptr+str.length);
}

/**
Convert nstring to unsigned integer
*/
T toInt(T)(nstring str, int base) if (isUnsigned!T && isIntegral!T) {
T toInt(T)(nstring str, int base) nothrow if (isUnsigned!T && isIntegral!T) {
const(char)* ptr = str.toCString();
return cast(T)strtoull(ptr, ptr+str.size(), base);
}

/**
Convert string slice to unsigned integer
*/
T toInt(T)(string str, int base) if (isUnsigned!T && isIntegral!T) {
T toInt(T)(string str, int base) nothrow if (isUnsigned!T && isIntegral!T) {
return cast(T)strtoull(str.ptr, str.ptr+str.length, base);
}

/**
Convert nstring to float
*/
T toFloat(T)(nstring str) if (isFloatingPoint!T) {
T toFloat(T)(nstring str) nothrow if (isFloatingPoint!T) {
return cast(T)atof(str.toCString());
}

/**
Convert string slice to float
*/
T toFloat(T)(string str) if (isFloatingPoint!T) {
T toFloat(T)(string str) nothrow if (isFloatingPoint!T) {
return cast(T)strtof(str.ptr, str.ptr+str.length);
}

Expand Down

0 comments on commit 0cbecd3

Please sign in to comment.