| 204 | }; |
| 205 | |
| 206 | Status GetErrorOptions(OpKernelConstruction* ctx, ErrorOptions* out) { |
| 207 | *out = ErrorOptions(); |
| 208 | |
| 209 | string error_policy; |
| 210 | TF_RETURN_IF_ERROR(ctx->GetAttr("errors", &error_policy)); |
| 211 | |
| 212 | if (error_policy == "replace") { |
| 213 | out->elide_replacement = false; |
| 214 | } else if (error_policy == "ignore") { |
| 215 | out->elide_replacement = true; |
| 216 | } else if (error_policy == "strict") { |
| 217 | out->error_on_malformatting = true; |
| 218 | } else { |
| 219 | return errors::InvalidArgument( |
| 220 | "errors policy must be one of 'strict', 'replace', or 'ignore'"); |
| 221 | } |
| 222 | |
| 223 | int32 replacement_char; |
| 224 | TF_RETURN_IF_ERROR(ctx->GetAttr("replacement_char", &replacement_char)); |
| 225 | |
| 226 | if (replacement_char >= UCHAR_MIN_VALUE && |
| 227 | replacement_char <= UCHAR_MAX_VALUE) { |
| 228 | out->subst = replacement_char; |
| 229 | } else { |
| 230 | return errors::InvalidArgument( |
| 231 | "replacement_char out of unicode codepoint range"); |
| 232 | } |
| 233 | |
| 234 | if (ctx->HasAttr("replace_control_characters")) { |
| 235 | TF_RETURN_IF_ERROR(ctx->GetAttr("replace_control_characters", |
| 236 | &(out->replace_control_chars))); |
| 237 | } |
| 238 | |
| 239 | return Status::OK(); |
| 240 | } |
| 241 | |
| 242 | inline bool ShouldHandleFormatError(const ErrorOptions& error_options, |
| 243 | UChar32 ch, bool format_error) { |
no test coverage detected