Skip to content

Commit

Permalink
Merge pull request #1791 from xlsynth:cdleary/2024-12-11-fmt-prefs
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 705969784
  • Loading branch information
copybara-github committed Dec 13, 2024
2 parents 9e49141 + 5c0974c commit 6d9fcb0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions xls/public/c_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ bool xls_format_preference_from_string(const char* s, char** error_out,
*result_out = xls_format_preference_plain_binary;
} else if (got == "plain_hex") {
*result_out = xls_format_preference_plain_hex;
} else if (got == "zero_padded_binary") {
*result_out = xls_format_preference_zero_padded_binary;
} else if (got == "zero_padded_hex") {
*result_out = xls_format_preference_zero_padded_hex;
} else {
absl::Status error = absl::InvalidArgumentError(absl::StrFormat(
"Invalid value for conversion to XLS format preference: `%s`", s));
Expand Down
2 changes: 2 additions & 0 deletions xls/public/c_api_format_preference.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ enum {
xls_format_preference_hex,
xls_format_preference_plain_binary,
xls_format_preference_plain_hex,
xls_format_preference_zero_padded_binary,
xls_format_preference_zero_padded_hex,
};

} // extern "C"
Expand Down
6 changes: 6 additions & 0 deletions xls/public/c_api_impl_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ bool FormatPreferenceFromC(xls_format_preference c_pref,
case xls_format_preference_plain_hex:
*cpp_pref = xls::FormatPreference::kPlainHex;
break;
case xls_format_preference_zero_padded_binary:
*cpp_pref = xls::FormatPreference::kZeroPaddedBinary;
break;
case xls_format_preference_zero_padded_hex:
*cpp_pref = xls::FormatPreference::kZeroPaddedHex;
break;
default:
*error_out = ToOwnedCString(
absl::StrFormat("Invalid format preference value: %d", c_pref));
Expand Down

0 comments on commit 6d9fcb0

Please sign in to comment.