@@ -57,6 +57,18 @@ const SplitIterator = fltiter.SplitIterator;
57
57
const IteratorInterface = fltiter .IteratorInterface ;
58
58
const IteratorMode = fltiter .IteratorMode ;
59
59
60
+ ////////////////////////////////////////////////////////////////////////////////
61
+ // ENUM IMPORTS ///
62
+ ////////////////////////////////////////////////////////////////////////////////
63
+ const fltenum = @import ("fluent_enum.zig" );
64
+ const StringMode = fltenum .StringMode ;
65
+ const DirectionOption = fltenum .DirectionOption ;
66
+ const ReplaceOption = fltenum .ReplaceOption ;
67
+ const TrimOptions = fltenum .TrimOptions ;
68
+ const SortDirection = fltenum .SortDirection ;
69
+ const SampleOption = fltenum .SampleOption ;
70
+ const FluentMode = fltenum .FluentMode ;
71
+
60
72
////////////////////////////////////////////////////////////////////////////////
61
73
// Public Fluent Interface Access Point ///
62
74
////////////////////////////////////////////////////////////////////////////////
@@ -125,11 +137,6 @@ pub fn FluentInterface(comptime T: type) type {
125
137
}
126
138
}
127
139
128
- // NOTE:
129
- // using slices here because this makes it directly
130
- // obvious that we're support any kind of slice and
131
- // both Mutable and Immutable backends.
132
-
133
140
///order - returns the lexicographical order compared to a given slice
134
141
pub fn order (self : Self , items : []const Self.DataType ) Order {
135
142
return std .mem .order (Self .DataType , self .items , items );
@@ -272,9 +279,7 @@ pub fn FluentInterface(comptime T: type) type {
272
279
) BaseIterator (DataType , mode ) {
273
280
return Fluent .iterator (mode , self .items );
274
281
}
275
- ////////////////////////////////////////////////////////////////////////////////
276
- /// GeneralImmutableBackend ///
277
- ////////////////////////////////////////////////////////////////////////////////
282
+
278
283
pub fn findFrom (
279
284
self : Self ,
280
285
comptime mode : FluentMode ,
@@ -597,33 +602,6 @@ pub fn FluentInterface(comptime T: type) type {
597
602
return self ;
598
603
}
599
604
600
- };
601
- }
602
-
603
-
604
- const StringMode = enum { regex , scalar };
605
-
606
- fn ImmutableStringBackend (comptime Self : type ) type {
607
- return struct {
608
-
609
-
610
- ////////////////////////////////////////////////////////////////////////////////
611
- // MUTABLE BACKEND : //
612
- // //
613
- // Only activated if the child data type is u8 //
614
- ////////////////////////////////////////////////////////////////////////////////
615
-
616
- fn MutableStringBackend (comptime Self : type ) type {
617
- return struct {
618
-
619
- ///////////////////////
620
- // PUBLIC SECTION //
621
- ///////////////////////
622
-
623
- pub usingnamespace ImmutableStringBackend (Self );
624
-
625
- pub usingnamespace GeneralMutableBackend (Self );
626
-
627
605
/// lower - transform all alphabetic characters to lower case
628
606
pub fn lower (self : Self ) Self {
629
607
for (self .items ) | * c | c .* = std .ascii .toLower (c .* );
@@ -721,142 +699,9 @@ fn MutableStringBackend(comptime Self: type) type {
721
699
}
722
700
return self ;
723
701
}
724
-
725
- ///////////////////////
726
- // PRIVATE SECTION //
727
- ///////////////////////
728
-
729
702
};
730
703
}
731
704
732
- //////////////////////////////////////////////////////////////////////////////////
733
- // STRING BIT SET : //
734
- //////////////////////////////////////////////////////////////////////////////////
735
-
736
- const StringBitSet = struct {
737
- const BackingSet = std .StaticBitSet (@bitSizeOf (usize ));
738
-
739
- bits : [4 ]BackingSet ,
740
-
741
- /// init - returns an initEmpty instance of StringBitSet
742
- pub fn init () StringBitSet {
743
- return .{ .bits = .{
744
- BackingSet .initEmpty (),
745
- BackingSet .initEmpty (),
746
- BackingSet .initEmpty (),
747
- BackingSet .initEmpty (),
748
- } };
749
- }
750
-
751
- /// setValue - sets the value of the bit at the specified position
752
- pub fn setValue (self : * StringBitSet , pos : usize , value : bool ) void {
753
- const mod_pos = pos & 63 ;
754
- switch (pos ) {
755
- 0... 63 = > self .bits [0 ].setValue (mod_pos , value ),
756
- 64... 127 = > self .bits [1 ].setValue (mod_pos , value ),
757
- 128... 191 = > self .bits [2 ].setValue (mod_pos , value ),
758
- 192... 255 = > self .bits [3 ].setValue (mod_pos , value ),
759
- else = > unreachable ,
760
- }
761
- }
762
-
763
- /// isSet - checks if the bit at the specified position is set
764
- pub fn isSet (self : * const StringBitSet , pos : usize ) bool {
765
- const mod_pos = pos & 63 ;
766
- return switch (pos ) {
767
- 0... 63 = > self .bits [0 ].isSet (mod_pos ),
768
- 64... 127 = > self .bits [1 ].isSet (mod_pos ),
769
- 128... 191 = > self .bits [2 ].isSet (mod_pos ),
770
- 192... 255 = > self .bits [3 ].isSet (mod_pos ),
771
- else = > unreachable ,
772
- };
773
- }
774
-
775
- /// unionWith - computes the union of two StringBitSets
776
- pub fn unionWith (self : StringBitSet , other : StringBitSet ) StringBitSet {
777
- return .{ .bits = .{
778
- self .bits [0 ].unionWith (other .bits [0 ]),
779
- self .bits [1 ].unionWith (other .bits [1 ]),
780
- self .bits [2 ].unionWith (other .bits [2 ]),
781
- self .bits [3 ].unionWith (other .bits [3 ]),
782
- } };
783
- }
784
-
785
- /// differenceWith - computes the difference of two StringBitSets
786
- pub fn differenceWith (self : StringBitSet , other : StringBitSet ) StringBitSet {
787
- return .{ .bits = .{
788
- self .bits [0 ].differenceWith (other .bits [0 ]),
789
- self .bits [1 ].differenceWith (other .bits [1 ]),
790
- self .bits [2 ].differenceWith (other .bits [2 ]),
791
- self .bits [3 ].differenceWith (other .bits [3 ]),
792
- } };
793
- }
794
-
795
- /// intersectWith - computes the intersection of two StringBitSets
796
- pub fn intersectWith (self : StringBitSet , other : StringBitSet ) StringBitSet {
797
- return .{ .bits = .{
798
- self .bits [0 ].intersectWith (other .bits [0 ]),
799
- self .bits [1 ].intersectWith (other .bits [1 ]),
800
- self .bits [2 ].intersectWith (other .bits [2 ]),
801
- self .bits [3 ].intersectWith (other .bits [3 ]),
802
- } };
803
- }
804
-
805
- /// count - counts the number of set bits in the StringBitSet
806
- pub fn count (self : StringBitSet ) usize {
807
- return self .bits [0 ].count () + self .bits [1 ].count () + self .bits [2 ].count () + self .bits [3 ].count ();
808
- }
809
-
810
- /// fillBuffer - fills a buffer with the values of set bits in the StringBitSet
811
- pub fn fillBuffer (self : * const StringBitSet , buffer : []u8 ) []u8 {
812
- var val : usize = 0 ;
813
- var pos : usize = 0 ;
814
- while (val < 256 ) : (val += 1 ) {
815
- if (self .isSet (val )) {
816
- buffer [pos ] = @intCast (val );
817
- pos += 1 ;
818
- }
819
- }
820
- return buffer [0.. pos ];
821
- }
822
- };
823
-
824
- //////////////////////////////////////////////////////////////////////////////////
825
- // ENUMERATED OPTIONS : //
826
- //////////////////////////////////////////////////////////////////////////////////
827
-
828
- const DirectionOption = enum {
829
- all ,
830
- left ,
831
- right ,
832
- };
833
-
834
- const ReplaceOption = enum {
835
- first ,
836
- last ,
837
- all ,
838
- periphery ,
839
- };
840
-
841
- const TrimOptions = enum {
842
- scalar ,
843
- predicate ,
844
- any ,
845
- };
846
-
847
- const SortDirection = enum {
848
- asc ,
849
- desc ,
850
- };
851
-
852
- const SampleOption = enum {
853
- scalar ,
854
- sequence ,
855
- };
856
-
857
- // any, sequence, scalar
858
- const FluentMode = std .mem .DelimiterType ;
859
-
860
705
////////////////////////////////////////////////////////////////////////////////
861
706
// TESTING BLOCK : ///
862
707
////////////////////////////////////////////////////////////////////////////////
0 commit comments