Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Address XXX, make static constants for strings used when stringify... #5178

Merged
merged 1 commit into from
Mar 1, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/libcore/num/strconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,17 +478,16 @@ pub pure fn from_str_bytes_common<T:NumCast+Zero+One+Ord+Copy+Div<T,T>+
}
}

// XXX: Bytevector constant from str
if special {
if buf == str::to_bytes("inf") || buf == str::to_bytes("+inf") {
if buf == str::inf_buf || buf == str::positive_inf_buf {
return NumStrConv::inf();
} else if buf == str::to_bytes("-inf") {
} else if buf == str::negative_inf_buf {
if negative {
return NumStrConv::neg_inf();
} else {
return None;
}
} else if buf == str::to_bytes("NaN") {
} else if buf == str::nan_buf {
return NumStrConv::NaN();
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1832,6 +1832,13 @@ const tag_five_b: uint = 248u;
const max_five_b: uint = 67108864u;
const tag_six_b: uint = 252u;

// Constants used for converting strs to floats
pub const inf_buf: [u8*3] = ['i' as u8, 'n' as u8, 'f' as u8];
pub const positive_inf_buf: [u8*4] = ['+' as u8, 'i' as u8,
'n' as u8, 'f' as u8];
pub const negative_inf_buf: [u8*4] = ['-' as u8, 'i' as u8,
'n' as u8, 'f' as u8];
pub const nan_buf: [u8*3] = ['N' as u8, 'a' as u8, 'N' as u8];

/**
* Work with the byte buffer of a string.
Expand Down