1use core::{mem, num};
4
5use static_assertions::const_assert;
6
7use crate::format_flags as flags;
8
9pub type OptionU8 = Option<num::NonZeroU8>;
11
12const_assert!(mem::size_of::<OptionU8>() == mem::size_of::<u8>());
14
15macro_rules! add_flag {
17 ($format:ident, $bool:expr, $flag:ident) => {
18 if $bool {
19 $format |= flags::$flag;
20 }
21 };
22}
23
24macro_rules! add_flags {
26 ($format:ident ; $($bool:expr, $flag:ident ;)*) => {{
27 $(add_flag!($format, $bool, $flag);)*
28 }};
29}
30
31macro_rules! has_flag {
33 ($format:ident, $flag:ident) => {
34 $format & flags::$flag != 0
35 };
36}
37
38#[inline(always)]
40const fn unwrap_or_zero(option: OptionU8) -> u8 {
41 match option {
42 Some(x) => x.get(),
43 None => 0,
44 }
45}
46
47pub struct NumberFormatBuilder {
197 digit_separator: OptionU8,
198 base_prefix: OptionU8,
199 base_suffix: OptionU8,
200 mantissa_radix: u8,
201 exponent_base: OptionU8,
202 exponent_radix: OptionU8,
203 required_integer_digits: bool,
204 required_fraction_digits: bool,
205 required_exponent_digits: bool,
206 required_mantissa_digits: bool,
207 no_positive_mantissa_sign: bool,
208 required_mantissa_sign: bool,
209 no_exponent_notation: bool,
210 no_positive_exponent_sign: bool,
211 required_exponent_sign: bool,
212 no_exponent_without_fraction: bool,
213 no_special: bool,
214 case_sensitive_special: bool,
215 no_integer_leading_zeros: bool,
216 no_float_leading_zeros: bool,
217 required_exponent_notation: bool,
218 case_sensitive_exponent: bool,
219 case_sensitive_base_prefix: bool,
220 case_sensitive_base_suffix: bool,
221 integer_internal_digit_separator: bool,
222 fraction_internal_digit_separator: bool,
223 exponent_internal_digit_separator: bool,
224 integer_leading_digit_separator: bool,
225 fraction_leading_digit_separator: bool,
226 exponent_leading_digit_separator: bool,
227 integer_trailing_digit_separator: bool,
228 fraction_trailing_digit_separator: bool,
229 exponent_trailing_digit_separator: bool,
230 integer_consecutive_digit_separator: bool,
231 fraction_consecutive_digit_separator: bool,
232 exponent_consecutive_digit_separator: bool,
233 special_digit_separator: bool,
234}
235
236impl NumberFormatBuilder {
237 #[inline(always)]
241 pub const fn new() -> Self {
242 Self {
243 digit_separator: None,
244 base_prefix: None,
245 base_suffix: None,
246 mantissa_radix: 10,
247 exponent_base: None,
248 exponent_radix: None,
249 required_integer_digits: false,
250 required_fraction_digits: false,
251 required_exponent_digits: true,
252 required_mantissa_digits: true,
253 no_positive_mantissa_sign: false,
254 required_mantissa_sign: false,
255 no_exponent_notation: false,
256 no_positive_exponent_sign: false,
257 required_exponent_sign: false,
258 no_exponent_without_fraction: false,
259 no_special: false,
260 case_sensitive_special: false,
261 no_integer_leading_zeros: false,
262 no_float_leading_zeros: false,
263 required_exponent_notation: false,
264 case_sensitive_exponent: false,
265 case_sensitive_base_prefix: false,
266 case_sensitive_base_suffix: false,
267 integer_internal_digit_separator: false,
268 fraction_internal_digit_separator: false,
269 exponent_internal_digit_separator: false,
270 integer_leading_digit_separator: false,
271 fraction_leading_digit_separator: false,
272 exponent_leading_digit_separator: false,
273 integer_trailing_digit_separator: false,
274 fraction_trailing_digit_separator: false,
275 exponent_trailing_digit_separator: false,
276 integer_consecutive_digit_separator: false,
277 fraction_consecutive_digit_separator: false,
278 exponent_consecutive_digit_separator: false,
279 special_digit_separator: false,
280 }
281 }
282
283 #[cfg(feature = "power-of-two")]
285 pub const fn binary() -> u128 {
286 Self::from_radix(2)
287 }
288
289 #[cfg(feature = "power-of-two")]
291 pub const fn octal() -> u128 {
292 Self::from_radix(8)
293 }
294
295 pub const fn decimal() -> u128 {
297 let mut builder = Self::new();
298 builder.mantissa_radix = 10;
299 builder.exponent_base = num::NonZeroU8::new(10);
300 builder.exponent_radix = num::NonZeroU8::new(10);
301 builder.build()
302 }
303
304 #[cfg(feature = "power-of-two")]
306 pub const fn hexadecimal() -> u128 {
307 Self::from_radix(16)
308 }
309
310 #[cfg(feature = "power-of-two")]
312 pub const fn from_radix(radix: u8) -> u128 {
313 Self::new()
314 .radix(radix)
315 .exponent_base(num::NonZeroU8::new(radix))
316 .exponent_radix(num::NonZeroU8::new(radix))
317 .build()
318 }
319
320 #[inline(always)]
324 pub const fn get_digit_separator(&self) -> OptionU8 {
325 self.digit_separator
326 }
327
328 #[inline(always)]
330 pub const fn get_mantissa_radix(&self) -> u8 {
331 self.mantissa_radix
332 }
333
334 #[inline(always)]
336 pub const fn get_exponent_base(&self) -> OptionU8 {
337 self.exponent_base
338 }
339
340 #[inline(always)]
342 pub const fn get_exponent_radix(&self) -> OptionU8 {
343 self.exponent_radix
344 }
345
346 #[inline(always)]
348 pub const fn get_base_prefix(&self) -> OptionU8 {
349 self.base_prefix
350 }
351
352 #[inline(always)]
354 pub const fn get_base_suffix(&self) -> OptionU8 {
355 self.base_suffix
356 }
357
358 #[inline(always)]
360 pub const fn get_required_integer_digits(&self) -> bool {
361 self.required_integer_digits
362 }
363
364 #[inline(always)]
366 pub const fn get_required_fraction_digits(&self) -> bool {
367 self.required_fraction_digits
368 }
369
370 #[inline(always)]
372 pub const fn get_required_exponent_digits(&self) -> bool {
373 self.required_exponent_digits
374 }
375
376 #[inline(always)]
378 pub const fn get_required_mantissa_digits(&self) -> bool {
379 self.required_mantissa_digits
380 }
381
382 #[inline(always)]
384 pub const fn get_no_positive_mantissa_sign(&self) -> bool {
385 self.no_positive_mantissa_sign
386 }
387
388 #[inline(always)]
390 pub const fn get_required_mantissa_sign(&self) -> bool {
391 self.required_mantissa_sign
392 }
393
394 #[inline(always)]
396 pub const fn get_no_exponent_notation(&self) -> bool {
397 self.no_exponent_notation
398 }
399
400 #[inline(always)]
402 pub const fn get_no_positive_exponent_sign(&self) -> bool {
403 self.no_positive_exponent_sign
404 }
405
406 #[inline(always)]
408 pub const fn get_required_exponent_sign(&self) -> bool {
409 self.required_exponent_sign
410 }
411
412 #[inline(always)]
414 pub const fn get_no_exponent_without_fraction(&self) -> bool {
415 self.no_exponent_without_fraction
416 }
417
418 #[inline(always)]
420 pub const fn get_no_special(&self) -> bool {
421 self.no_special
422 }
423
424 #[inline(always)]
426 pub const fn get_case_sensitive_special(&self) -> bool {
427 self.case_sensitive_special
428 }
429
430 #[inline(always)]
432 pub const fn get_no_integer_leading_zeros(&self) -> bool {
433 self.no_integer_leading_zeros
434 }
435
436 #[inline(always)]
438 pub const fn get_no_float_leading_zeros(&self) -> bool {
439 self.no_float_leading_zeros
440 }
441
442 #[inline(always)]
444 pub const fn get_required_exponent_notation(&self) -> bool {
445 self.required_exponent_notation
446 }
447
448 #[inline(always)]
450 pub const fn get_case_sensitive_exponent(&self) -> bool {
451 self.case_sensitive_exponent
452 }
453
454 #[inline(always)]
456 pub const fn get_case_sensitive_base_prefix(&self) -> bool {
457 self.case_sensitive_base_prefix
458 }
459
460 #[inline(always)]
462 pub const fn get_case_sensitive_base_suffix(&self) -> bool {
463 self.case_sensitive_base_suffix
464 }
465
466 #[inline(always)]
472 pub const fn get_integer_internal_digit_separator(&self) -> bool {
473 self.integer_internal_digit_separator
474 }
475
476 #[inline(always)]
482 pub const fn get_fraction_internal_digit_separator(&self) -> bool {
483 self.fraction_internal_digit_separator
484 }
485
486 #[inline(always)]
492 pub const fn get_exponent_internal_digit_separator(&self) -> bool {
493 self.exponent_internal_digit_separator
494 }
495
496 #[inline(always)]
501 pub const fn get_integer_leading_digit_separator(&self) -> bool {
502 self.integer_leading_digit_separator
503 }
504
505 #[inline(always)]
510 pub const fn get_fraction_leading_digit_separator(&self) -> bool {
511 self.fraction_leading_digit_separator
512 }
513
514 #[inline(always)]
519 pub const fn get_exponent_leading_digit_separator(&self) -> bool {
520 self.exponent_leading_digit_separator
521 }
522
523 #[inline(always)]
528 pub const fn get_integer_trailing_digit_separator(&self) -> bool {
529 self.integer_trailing_digit_separator
530 }
531
532 #[inline(always)]
537 pub const fn get_fraction_trailing_digit_separator(&self) -> bool {
538 self.fraction_trailing_digit_separator
539 }
540
541 #[inline(always)]
546 pub const fn get_exponent_trailing_digit_separator(&self) -> bool {
547 self.exponent_trailing_digit_separator
548 }
549
550 #[inline(always)]
552 pub const fn get_integer_consecutive_digit_separator(&self) -> bool {
553 self.integer_consecutive_digit_separator
554 }
555
556 #[inline(always)]
558 pub const fn get_fraction_consecutive_digit_separator(&self) -> bool {
559 self.fraction_consecutive_digit_separator
560 }
561
562 #[inline(always)]
564 pub const fn get_exponent_consecutive_digit_separator(&self) -> bool {
565 self.exponent_consecutive_digit_separator
566 }
567
568 #[inline(always)]
570 pub const fn get_special_digit_separator(&self) -> bool {
571 self.special_digit_separator
572 }
573
574 #[inline(always)]
578 #[cfg(feature = "format")]
579 pub const fn digit_separator(mut self, character: OptionU8) -> Self {
580 self.digit_separator = character;
581 self
582 }
583
584 #[inline(always)]
586 #[cfg(feature = "power-of-two")]
587 pub const fn radix(self, radix: u8) -> Self {
588 self.mantissa_radix(radix)
589 }
590
591 #[inline(always)]
593 #[cfg(feature = "power-of-two")]
594 pub const fn mantissa_radix(mut self, radix: u8) -> Self {
595 self.mantissa_radix = radix;
596 self
597 }
598
599 #[inline(always)]
601 #[cfg(feature = "power-of-two")]
602 pub const fn exponent_base(mut self, base: OptionU8) -> Self {
603 self.exponent_base = base;
604 self
605 }
606
607 #[inline(always)]
609 #[cfg(feature = "power-of-two")]
610 pub const fn exponent_radix(mut self, radix: OptionU8) -> Self {
611 self.exponent_radix = radix;
612 self
613 }
614
615 #[inline(always)]
617 #[cfg(all(feature = "power-of-two", feature = "format"))]
618 pub const fn base_prefix(mut self, base_prefix: OptionU8) -> Self {
619 self.base_prefix = base_prefix;
620 self
621 }
622
623 #[inline(always)]
625 #[cfg(all(feature = "power-of-two", feature = "format"))]
626 pub const fn base_suffix(mut self, base_suffix: OptionU8) -> Self {
627 self.base_suffix = base_suffix;
628 self
629 }
630
631 #[inline(always)]
633 #[cfg(feature = "format")]
634 pub const fn required_integer_digits(mut self, flag: bool) -> Self {
635 self.required_integer_digits = flag;
636 self
637 }
638
639 #[inline(always)]
641 #[cfg(feature = "format")]
642 pub const fn required_fraction_digits(mut self, flag: bool) -> Self {
643 self.required_fraction_digits = flag;
644 self
645 }
646
647 #[inline(always)]
649 #[cfg(feature = "format")]
650 pub const fn required_exponent_digits(mut self, flag: bool) -> Self {
651 self.required_exponent_digits = flag;
652 self
653 }
654
655 #[inline(always)]
657 #[cfg(feature = "format")]
658 pub const fn required_mantissa_digits(mut self, flag: bool) -> Self {
659 self.required_mantissa_digits = flag;
660 self
661 }
662
663 #[inline(always)]
665 #[cfg(feature = "format")]
666 pub const fn required_digits(mut self, flag: bool) -> Self {
667 self = self.required_integer_digits(flag);
668 self = self.required_fraction_digits(flag);
669 self = self.required_exponent_digits(flag);
670 self = self.required_mantissa_digits(flag);
671 self
672 }
673
674 #[inline(always)]
676 #[cfg(feature = "format")]
677 pub const fn no_positive_mantissa_sign(mut self, flag: bool) -> Self {
678 self.no_positive_mantissa_sign = flag;
679 self
680 }
681
682 #[inline(always)]
684 #[cfg(feature = "format")]
685 pub const fn required_mantissa_sign(mut self, flag: bool) -> Self {
686 self.required_mantissa_sign = flag;
687 self
688 }
689
690 #[inline(always)]
692 #[cfg(feature = "format")]
693 pub const fn no_exponent_notation(mut self, flag: bool) -> Self {
694 self.no_exponent_notation = flag;
695 self
696 }
697
698 #[inline(always)]
700 #[cfg(feature = "format")]
701 pub const fn no_positive_exponent_sign(mut self, flag: bool) -> Self {
702 self.no_positive_exponent_sign = flag;
703 self
704 }
705
706 #[inline(always)]
708 #[cfg(feature = "format")]
709 pub const fn required_exponent_sign(mut self, flag: bool) -> Self {
710 self.required_exponent_sign = flag;
711 self
712 }
713
714 #[inline(always)]
716 #[cfg(feature = "format")]
717 pub const fn no_exponent_without_fraction(mut self, flag: bool) -> Self {
718 self.no_exponent_without_fraction = flag;
719 self
720 }
721
722 #[inline(always)]
724 #[cfg(feature = "format")]
725 pub const fn no_special(mut self, flag: bool) -> Self {
726 self.no_special = flag;
727 self
728 }
729
730 #[inline(always)]
732 #[cfg(feature = "format")]
733 pub const fn case_sensitive_special(mut self, flag: bool) -> Self {
734 self.case_sensitive_special = flag;
735 self
736 }
737
738 #[inline(always)]
740 #[cfg(feature = "format")]
741 pub const fn no_integer_leading_zeros(mut self, flag: bool) -> Self {
742 self.no_integer_leading_zeros = flag;
743 self
744 }
745
746 #[inline(always)]
748 #[cfg(feature = "format")]
749 pub const fn no_float_leading_zeros(mut self, flag: bool) -> Self {
750 self.no_float_leading_zeros = flag;
751 self
752 }
753
754 #[inline(always)]
756 #[cfg(feature = "format")]
757 pub const fn required_exponent_notation(mut self, flag: bool) -> Self {
758 self.required_exponent_notation = flag;
759 self
760 }
761
762 #[inline(always)]
764 #[cfg(feature = "format")]
765 pub const fn case_sensitive_exponent(mut self, flag: bool) -> Self {
766 self.case_sensitive_exponent = flag;
767 self
768 }
769
770 #[inline(always)]
772 #[cfg(all(feature = "power-of-two", feature = "format"))]
773 pub const fn case_sensitive_base_prefix(mut self, flag: bool) -> Self {
774 self.case_sensitive_base_prefix = flag;
775 self
776 }
777
778 #[inline(always)]
780 #[cfg(all(feature = "power-of-two", feature = "format"))]
781 pub const fn case_sensitive_base_suffix(mut self, flag: bool) -> Self {
782 self.case_sensitive_base_suffix = flag;
783 self
784 }
785
786 #[inline(always)]
792 #[cfg(feature = "format")]
793 pub const fn integer_internal_digit_separator(mut self, flag: bool) -> Self {
794 self.integer_internal_digit_separator = flag;
795 self
796 }
797
798 #[inline(always)]
804 #[cfg(feature = "format")]
805 pub const fn fraction_internal_digit_separator(mut self, flag: bool) -> Self {
806 self.fraction_internal_digit_separator = flag;
807 self
808 }
809
810 #[inline(always)]
816 #[cfg(feature = "format")]
817 pub const fn exponent_internal_digit_separator(mut self, flag: bool) -> Self {
818 self.exponent_internal_digit_separator = flag;
819 self
820 }
821
822 #[inline(always)]
828 #[cfg(feature = "format")]
829 pub const fn internal_digit_separator(mut self, flag: bool) -> Self {
830 self = self.integer_internal_digit_separator(flag);
831 self = self.fraction_internal_digit_separator(flag);
832 self = self.exponent_internal_digit_separator(flag);
833 self
834 }
835
836 #[inline(always)]
841 #[cfg(feature = "format")]
842 pub const fn integer_leading_digit_separator(mut self, flag: bool) -> Self {
843 self.integer_leading_digit_separator = flag;
844 self
845 }
846
847 #[inline(always)]
852 #[cfg(feature = "format")]
853 pub const fn fraction_leading_digit_separator(mut self, flag: bool) -> Self {
854 self.fraction_leading_digit_separator = flag;
855 self
856 }
857
858 #[inline(always)]
863 #[cfg(feature = "format")]
864 pub const fn exponent_leading_digit_separator(mut self, flag: bool) -> Self {
865 self.exponent_leading_digit_separator = flag;
866 self
867 }
868
869 #[inline(always)]
874 #[cfg(feature = "format")]
875 pub const fn leading_digit_separator(mut self, flag: bool) -> Self {
876 self = self.integer_leading_digit_separator(flag);
877 self = self.fraction_leading_digit_separator(flag);
878 self = self.exponent_leading_digit_separator(flag);
879 self
880 }
881
882 #[inline(always)]
887 #[cfg(feature = "format")]
888 pub const fn integer_trailing_digit_separator(mut self, flag: bool) -> Self {
889 self.integer_trailing_digit_separator = flag;
890 self
891 }
892
893 #[inline(always)]
898 #[cfg(feature = "format")]
899 pub const fn fraction_trailing_digit_separator(mut self, flag: bool) -> Self {
900 self.fraction_trailing_digit_separator = flag;
901 self
902 }
903
904 #[inline(always)]
909 #[cfg(feature = "format")]
910 pub const fn exponent_trailing_digit_separator(mut self, flag: bool) -> Self {
911 self.exponent_trailing_digit_separator = flag;
912 self
913 }
914
915 #[inline(always)]
920 #[cfg(feature = "format")]
921 pub const fn trailing_digit_separator(mut self, flag: bool) -> Self {
922 self = self.integer_trailing_digit_separator(flag);
923 self = self.fraction_trailing_digit_separator(flag);
924 self = self.exponent_trailing_digit_separator(flag);
925 self
926 }
927
928 #[inline(always)]
930 #[cfg(feature = "format")]
931 pub const fn integer_consecutive_digit_separator(mut self, flag: bool) -> Self {
932 self.integer_consecutive_digit_separator = flag;
933 self
934 }
935
936 #[inline(always)]
938 #[cfg(feature = "format")]
939 pub const fn fraction_consecutive_digit_separator(mut self, flag: bool) -> Self {
940 self.fraction_consecutive_digit_separator = flag;
941 self
942 }
943
944 #[inline(always)]
946 #[cfg(feature = "format")]
947 pub const fn exponent_consecutive_digit_separator(mut self, flag: bool) -> Self {
948 self.exponent_consecutive_digit_separator = flag;
949 self
950 }
951
952 #[inline(always)]
954 #[cfg(feature = "format")]
955 pub const fn consecutive_digit_separator(mut self, flag: bool) -> Self {
956 self = self.integer_consecutive_digit_separator(flag);
957 self = self.fraction_consecutive_digit_separator(flag);
958 self = self.exponent_consecutive_digit_separator(flag);
959 self
960 }
961
962 #[inline(always)]
964 #[cfg(feature = "format")]
965 pub const fn special_digit_separator(mut self, flag: bool) -> Self {
966 self.special_digit_separator = flag;
967 self
968 }
969
970 #[inline(always)]
972 #[cfg(feature = "format")]
973 pub const fn digit_separator_flags(mut self, flag: bool) -> Self {
974 self = self.integer_digit_separator_flags(flag);
975 self = self.fraction_digit_separator_flags(flag);
976 self = self.exponent_digit_separator_flags(flag);
977 self = self.special_digit_separator(flag);
978 self
979 }
980
981 #[inline(always)]
983 #[cfg(feature = "format")]
984 pub const fn integer_digit_separator_flags(mut self, flag: bool) -> Self {
985 self = self.integer_internal_digit_separator(flag);
986 self = self.integer_leading_digit_separator(flag);
987 self = self.integer_trailing_digit_separator(flag);
988 self = self.integer_consecutive_digit_separator(flag);
989 self
990 }
991
992 #[inline(always)]
994 #[cfg(feature = "format")]
995 pub const fn fraction_digit_separator_flags(mut self, flag: bool) -> Self {
996 self = self.fraction_internal_digit_separator(flag);
997 self = self.fraction_leading_digit_separator(flag);
998 self = self.fraction_trailing_digit_separator(flag);
999 self = self.fraction_consecutive_digit_separator(flag);
1000 self
1001 }
1002
1003 #[inline(always)]
1005 #[cfg(feature = "format")]
1006 pub const fn exponent_digit_separator_flags(mut self, flag: bool) -> Self {
1007 self = self.exponent_internal_digit_separator(flag);
1008 self = self.exponent_leading_digit_separator(flag);
1009 self = self.exponent_trailing_digit_separator(flag);
1010 self = self.exponent_consecutive_digit_separator(flag);
1011 self
1012 }
1013
1014 #[inline(always)]
1023 pub const fn build(&self) -> u128 {
1024 let mut format: u128 = 0;
1025 add_flags!(
1026 format ;
1027 self.required_integer_digits, REQUIRED_INTEGER_DIGITS ;
1028 self.required_fraction_digits, REQUIRED_FRACTION_DIGITS ;
1029 self.required_exponent_digits, REQUIRED_EXPONENT_DIGITS ;
1030 self.required_mantissa_digits, REQUIRED_MANTISSA_DIGITS ;
1031 self.no_positive_mantissa_sign, NO_POSITIVE_MANTISSA_SIGN ;
1032 self.required_mantissa_sign, REQUIRED_MANTISSA_SIGN ;
1033 self.no_exponent_notation, NO_EXPONENT_NOTATION ;
1034 self.no_positive_exponent_sign, NO_POSITIVE_EXPONENT_SIGN ;
1035 self.required_exponent_sign, REQUIRED_EXPONENT_SIGN ;
1036 self.no_exponent_without_fraction, NO_EXPONENT_WITHOUT_FRACTION ;
1037 self.no_special, NO_SPECIAL ;
1038 self.case_sensitive_special, CASE_SENSITIVE_SPECIAL ;
1039 self.no_integer_leading_zeros, NO_INTEGER_LEADING_ZEROS ;
1040 self.no_float_leading_zeros, NO_FLOAT_LEADING_ZEROS ;
1041 self.required_exponent_notation, REQUIRED_EXPONENT_NOTATION ;
1042 self.case_sensitive_exponent, CASE_SENSITIVE_EXPONENT ;
1043 self.case_sensitive_base_prefix, CASE_SENSITIVE_BASE_PREFIX ;
1044 self.case_sensitive_base_suffix, CASE_SENSITIVE_BASE_SUFFIX ;
1045 self.integer_internal_digit_separator, INTEGER_INTERNAL_DIGIT_SEPARATOR ;
1046 self.fraction_internal_digit_separator, FRACTION_INTERNAL_DIGIT_SEPARATOR ;
1047 self.exponent_internal_digit_separator, EXPONENT_INTERNAL_DIGIT_SEPARATOR ;
1048 self.integer_leading_digit_separator, INTEGER_LEADING_DIGIT_SEPARATOR ;
1049 self.fraction_leading_digit_separator, FRACTION_LEADING_DIGIT_SEPARATOR ;
1050 self.exponent_leading_digit_separator, EXPONENT_LEADING_DIGIT_SEPARATOR ;
1051 self.integer_trailing_digit_separator, INTEGER_TRAILING_DIGIT_SEPARATOR ;
1052 self.fraction_trailing_digit_separator, FRACTION_TRAILING_DIGIT_SEPARATOR ;
1053 self.exponent_trailing_digit_separator, EXPONENT_TRAILING_DIGIT_SEPARATOR ;
1054 self.integer_consecutive_digit_separator, INTEGER_CONSECUTIVE_DIGIT_SEPARATOR ;
1055 self.fraction_consecutive_digit_separator, FRACTION_CONSECUTIVE_DIGIT_SEPARATOR ;
1056 self.exponent_consecutive_digit_separator, EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR ;
1057 self.special_digit_separator, SPECIAL_DIGIT_SEPARATOR ;
1058 );
1059 if format & flags::DIGIT_SEPARATOR_FLAG_MASK != 0 {
1060 format |=
1061 (unwrap_or_zero(self.digit_separator) as u128) << flags::DIGIT_SEPARATOR_SHIFT;
1062 }
1063 format |= (unwrap_or_zero(self.base_prefix) as u128) << flags::BASE_PREFIX_SHIFT;
1064 format |= (unwrap_or_zero(self.base_suffix) as u128) << flags::BASE_SUFFIX_SHIFT;
1065 format |= (self.mantissa_radix as u128) << flags::MANTISSA_RADIX_SHIFT;
1066 format |= (unwrap_or_zero(self.exponent_base) as u128) << flags::EXPONENT_BASE_SHIFT;
1067 format |= (unwrap_or_zero(self.exponent_radix) as u128) << flags::EXPONENT_RADIX_SHIFT;
1068
1069 format
1070 }
1071
1072 #[inline(always)]
1074 pub const fn rebuild(format: u128) -> Self {
1075 NumberFormatBuilder {
1076 digit_separator: num::NonZeroU8::new(flags::digit_separator(format)),
1077 base_prefix: num::NonZeroU8::new(flags::base_prefix(format)),
1078 base_suffix: num::NonZeroU8::new(flags::base_suffix(format)),
1079 mantissa_radix: flags::mantissa_radix(format) as u8,
1080 exponent_base: num::NonZeroU8::new(flags::exponent_base(format) as u8),
1081 exponent_radix: num::NonZeroU8::new(flags::exponent_radix(format) as u8),
1082 required_integer_digits: has_flag!(format, REQUIRED_INTEGER_DIGITS),
1083 required_fraction_digits: has_flag!(format, REQUIRED_FRACTION_DIGITS),
1084 required_exponent_digits: has_flag!(format, REQUIRED_EXPONENT_DIGITS),
1085 required_mantissa_digits: has_flag!(format, REQUIRED_MANTISSA_DIGITS),
1086 no_positive_mantissa_sign: has_flag!(format, NO_POSITIVE_MANTISSA_SIGN),
1087 required_mantissa_sign: has_flag!(format, REQUIRED_MANTISSA_SIGN),
1088 no_exponent_notation: has_flag!(format, NO_EXPONENT_NOTATION),
1089 no_positive_exponent_sign: has_flag!(format, NO_POSITIVE_EXPONENT_SIGN),
1090 required_exponent_sign: has_flag!(format, REQUIRED_EXPONENT_SIGN),
1091 no_exponent_without_fraction: has_flag!(format, NO_EXPONENT_WITHOUT_FRACTION),
1092 no_special: has_flag!(format, NO_SPECIAL),
1093 case_sensitive_special: has_flag!(format, CASE_SENSITIVE_SPECIAL),
1094 no_integer_leading_zeros: has_flag!(format, NO_INTEGER_LEADING_ZEROS),
1095 no_float_leading_zeros: has_flag!(format, NO_FLOAT_LEADING_ZEROS),
1096 required_exponent_notation: has_flag!(format, REQUIRED_EXPONENT_NOTATION),
1097 case_sensitive_exponent: has_flag!(format, CASE_SENSITIVE_EXPONENT),
1098 case_sensitive_base_prefix: has_flag!(format, CASE_SENSITIVE_BASE_PREFIX),
1099 case_sensitive_base_suffix: has_flag!(format, CASE_SENSITIVE_BASE_SUFFIX),
1100 integer_internal_digit_separator: has_flag!(format, INTEGER_INTERNAL_DIGIT_SEPARATOR),
1101 fraction_internal_digit_separator: has_flag!(format, FRACTION_INTERNAL_DIGIT_SEPARATOR),
1102 exponent_internal_digit_separator: has_flag!(format, EXPONENT_INTERNAL_DIGIT_SEPARATOR),
1103 integer_leading_digit_separator: has_flag!(format, INTEGER_LEADING_DIGIT_SEPARATOR),
1104 fraction_leading_digit_separator: has_flag!(format, FRACTION_LEADING_DIGIT_SEPARATOR),
1105 exponent_leading_digit_separator: has_flag!(format, EXPONENT_LEADING_DIGIT_SEPARATOR),
1106 integer_trailing_digit_separator: has_flag!(format, INTEGER_TRAILING_DIGIT_SEPARATOR),
1107 fraction_trailing_digit_separator: has_flag!(format, FRACTION_TRAILING_DIGIT_SEPARATOR),
1108 exponent_trailing_digit_separator: has_flag!(format, EXPONENT_TRAILING_DIGIT_SEPARATOR),
1109 integer_consecutive_digit_separator: has_flag!(
1110 format,
1111 INTEGER_CONSECUTIVE_DIGIT_SEPARATOR
1112 ),
1113 fraction_consecutive_digit_separator: has_flag!(
1114 format,
1115 FRACTION_CONSECUTIVE_DIGIT_SEPARATOR
1116 ),
1117 exponent_consecutive_digit_separator: has_flag!(
1118 format,
1119 EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR
1120 ),
1121 special_digit_separator: has_flag!(format, SPECIAL_DIGIT_SEPARATOR),
1122 }
1123 }
1124}
1125
1126impl Default for NumberFormatBuilder {
1127 #[inline(always)]
1128 fn default() -> Self {
1129 Self::new()
1130 }
1131}