1 #Region "Microsoft.VisualBasic::63de4392770e77423d646f315a4dba4e, Microsoft.VisualBasic.Core\Language\Linq\Vectorization\StringVector.vb"
2
3     ' Author:
4     
5     '       asuka (amethyst.asuka@gcmodeller.org)
6     '       xie (genetics@smrucc.org)
7     '       xieguigang (xie.guigang@live.com)
8     
9     ' Copyright (c) 2018 GPL3 Licensed
10     
11     
12     ' GNU GENERAL PUBLIC LICENSE (GPL3)
13     
14     
15     ' This program is free software: you can redistribute it and/or modify
16     ' it under the terms of the GNU General Public License as published by
17     ' the Free Software Foundation, either version 3 of the License, or
18     ' (at your option) any later version.
19     
20     ' This program is distributed in the hope that it will be useful,
21     ' but WITHOUT ANY WARRANTY; without even the implied warranty of
22     ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23     ' GNU General Public License for more details.
24     
25     ' You should have received a copy of the GNU General Public License
26     ' along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28
29
30     ' /********************************************************************************/
31
32     ' Summaries:
33
34     '     Class StringVector
35     
36     '         Properties: Len
37     
38     '         Constructor: (+2 OverloadsSub New
39     '         FunctionInStr, IsPattern, ToString
40     '         Operators: <>, =
41     
42     
43     ' /********************************************************************************/
44
45 #End Region
46
47 Imports System.Runtime.CompilerServices
48 Imports System.Text.RegularExpressions
49 Imports Microsoft.VisualBasic.Linq
50 Imports Microsoft.VisualBasic.Serialization.JSON
51 Imports base = Microsoft.VisualBasic.Strings
52
53 Namespace Language.Vectorization
54
55     Public Class StringVector : Inherits Vector(Of String)
56
57         ''' <summary>
58         ''' Returns the length of each strings
59         ''' </summary>
60         ''' <returns></returns>
61         Public Overloads ReadOnly Property Len As IEnumerable(Of Integer)
62             Get
63                 Return Strings.Len(Me)
64             End Get
65         End Property
66
67         Sub New()
68         End Sub
69
70         Public Overrides Function ToString() As String
71             Return buffer.GetJson
72         End Function
73
74         <MethodImpl(MethodImplOptions.AggressiveInlining)>
75         Sub New(buffer As IEnumerable(Of String))
76             Me.buffer = buffer.SafeQuery.ToArray
77         End Sub
78
79         Public Shared Widening Operator CType(list As List(Of String)) As StringVector
80             Return New StringVector(list)
81         End Operator
82
83         Public Shared Widening Operator CType(array As String()) As StringVector
84             Return New StringVector(array)
85         End Operator
86
87         <MethodImpl(MethodImplOptions.AggressiveInlining)>
88         Public Overloads Shared Operator &(s1 As StringVector, s2$) As StringVector
89             Return New StringVector(s1.Select(Function(s) s & s2))
90         End Operator
91
92         <MethodImpl(MethodImplOptions.AggressiveInlining)>
93         Public Shared Operator <>(s1 As StringVector, s2$) As BooleanVector
94             Return Not s1 = s2
95         End Operator
96
97         <MethodImpl(MethodImplOptions.AggressiveInlining)>
98         Public Shared Operator =(s1 As StringVector, s2$) As BooleanVector
99             Return New BooleanVector(s1.Select(Function(s) s = s2))
100         End Operator
101
102         <MethodImpl(MethodImplOptions.AggressiveInlining)>
103         Public Shared Function InStr(string1 As StringVector, string2$, Optional method As CompareMethod = CompareMethod.Binary) As Vector(Of Integer)
104             Return string1.Select(Function(str) base.InStr(str, string2, method)).AsVector
105         End Function
106
107         <MethodImpl(MethodImplOptions.AggressiveInlining)>
108         Public Shared Function IsPattern(strings As StringVector, pattern$, Optional opt As RegexOptions = RegexICSng) As BooleanVector
109             Return strings.Select(Function(s) s.IsPattern(pattern, opt)).AsVector
110         End Function
111
112         ''' <summary>
113         ''' 
114         ''' </summary>
115         ''' <param name="expression">a,b,c,d,e</param>
116         ''' <returns></returns>
117         ''' 
118         <MethodImpl(MethodImplOptions.AggressiveInlining)>
119         Public Shared Widening Operator CType(expression As StringAs StringVector
120             Return New StringVector(base.Split(expression, ","))
121         End Operator
122     End Class
123 End Namespace