M_String：内部処理

# パターン作成
RegExp用パターンを作成する
## 検索パターン作成
~~~
'------------------------------------------------------------------------------
' パターン作成
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' 検索パターン作成
'------------------------------------------------------------------------------
Private Function PF_String_ReturnSearchPattern( _
        ByVal aSearch As String, ByVal aSrchSpec As E_STRING_SPEC) As String
    Dim wkRtn As String
    
    'エスケープシーケンス変換（必要分のみ）
    wkRtn = PF_String_ReturnChangeEscSeq(aSearch, Array("\", "{", "}", "(", ")", "[", "]"))
    
    '開始側パターン設定
    If M_Common.F_CheckBitOn(aSrchSpec, E_STRING_SPEC_POS_START) = True Then
        wkRtn = F_String_ReturnAdd(wkRtn, "^", aAddSpec:=E_STRING_SPEC_POS_START)
    End If
            
    '終了側パターン設定
    If M_Common.F_CheckBitOn(aSrchSpec, E_STRING_SPEC_POS_END) = True Then
        wkRtn = F_String_ReturnAdd(wkRtn, "$", aExcluded:="\$")
    End If
    
    PF_String_ReturnSearchPattern = wkRtn
End Function

' エスケープシーケンス置換
Private Function PF_String_ReturnChangeEscSeq( _
        ByVal aSearch As String, _
        ByVal aEscSeqAry As Variant) As String
    Dim wkRtn As String
    Dim wkTmp As Variant
    
    '初期化
    wkRtn = aSearch
    
    'エスケープシーケンスに置き換え
    For Each wkTmp In aEscSeqAry
        wkRtn = Replace(wkRtn, wkTmp, "\" & wkTmp)
    Next wkTmp
    
    '初期化
    PF_String_ReturnChangeEscSeq = wkRtn
End Function
~~~
## チェックパターン作成
~~~
'------------------------------------------------------------------------------
' チェックパターン作成
'------------------------------------------------------------------------------
Private Function PF_String_ReturnCheckPattern( _
        ByVal aSrchPtn As String, ByVal aSrchSpec As E_STRING_SPEC, _
        ByVal aChkPtn As String, ByVal aChkSpec As E_STRING_SPEC) As String
    Dim wkRtn As String
    Dim wkPattern As String
    
    wkRtn = "(" & aSrchPtn & ")"
    
    '一致パターン追加ありの場合
    If aChkPtn <> "" And aChkSpec <> E_STRING_SPEC_NONE Then
        '開始側チェック指定あり、かつ開始側一致指定なしの場合、検索文字列開始側にチェックパターン追加
        If M_Common.F_CheckBitOn(aChkSpec, E_STRING_SPEC_MATCH_START) = True And _
                M_Common.F_CheckBitOn(aSrchSpec, E_STRING_SPEC_MATCH_START) <> True Then
            wkRtn = aChkPtn & wkRtn
        End If
        '終端側チェック指定あり、かつ終端側一致指定なしの場合、検索文字列終端側にチェックパターン追加
        If M_Common.F_CheckBitOn(aChkSpec, E_STRING_SPEC_MATCH_END) = True And _
                M_Common.F_CheckBitOn(aSrchSpec, E_STRING_SPEC_MATCH_END) <> True Then
            wkRtn = wkRtn & aChkPtn
        End If
    End If
    
    '開始側パターン設定
    If M_Common.F_CheckBitOn(aSrchSpec, E_STRING_SPEC_POS_START) = True Then
        wkRtn = F_String_ReturnAdd(wkRtn, "^", aAddSpec:=E_STRING_SPEC_POS_START)
    End If
            
    '終了側パターン設定
    If M_Common.F_CheckBitOn(aSrchSpec, E_STRING_SPEC_POS_END) = True Then
        wkRtn = F_String_ReturnAdd(wkRtn, "$", aExcluded:="\$")
    End If
    
    PF_String_ReturnCheckPattern = wkRtn
End Function
~~~
## 単語検索パターン作成
~~~
'------------------------------------------------------------------------------
' 単語検索パターン作成
'------------------------------------------------------------------------------
Private Function PF_String_ReturnCheckPatternWord( _
        ByVal aSrchPtn As String, ByVal aSrchSpec As E_STRING_SPEC, _
        ByVal aChkPtn As String, ByVal aChkSpec As E_STRING_SPEC) As String
    Dim wkRtn As String
    Dim wkTmpStr As String
    
    '中間検索指定ありの場合、中央検索指定
    If M_Common.F_CheckBitOn(aSrchSpec, E_STRING_SPEC_MATCH_MID) = True Then
        wkRtn = PF_String_ReturnCheckPattern(aSrchPtn, aSrchSpec, aChkPtn, aChkSpec)
    End If
        
    '先頭検索指定または中間検索指定あり、かつパターン指定に終端ありの場合
    If M_Common.F_CheckBitOn(aSrchSpec, (E_STRING_SPEC_MATCH_START Or E_STRING_SPEC_MATCH_MID)) = True And _
            M_Common.F_CheckBitOn(aSrchSpec, E_STRING_SPEC_MATCH_END) = True Then
        '開始位置一致確認を追加
        wkTmpStr = PF_String_ReturnCheckPattern(aSrchPtn, E_STRING_SPEC_MATCH_START, aChkPtn, E_STRING_SPEC_MATCH_END)
        wkRtn = F_String_ReturnAdd(wkRtn, wkTmpStr, aDlmt:="|")
    End If
        
    '終端検索指定または中間検索指定あり、かつパターン指定に先頭ありの場合
    If M_Common.F_CheckBitOn(aSrchSpec, (E_STRING_SPEC_MATCH_END Or E_STRING_SPEC_MATCH_MID)) = True And _
            M_Common.F_CheckBitOn(aSrchSpec, E_STRING_SPEC_MATCH_START) = True Then
        '終端位置一致確認を追加
        wkTmpStr = PF_String_ReturnCheckPattern(aSrchPtn, E_STRING_SPEC_MATCH_END, aChkPtn, E_STRING_SPEC_MATCH_START)
        wkRtn = F_String_ReturnAdd(wkRtn, wkTmpStr, aDlmt:="|")
    End If
    
    If wkRtn = "" Then
        wkRtn = aSrchPtn
    End If
    
    PF_String_ReturnCheckPatternWord = wkRtn
End Function
~~~
# 文字列調整
各種文字列関連の調整を実施する
## 終了位置調整
~~~
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' 文字列調整
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' 終了位置調整
'------------------------------------------------------------------------------
Private Function PF_String_GetPosEndAdjust( _
        ByRef aRtn As Long, _
        ByVal aLenMax As Long, _
        ByVal aSttPos As Long, _
        ByVal aLength As Long) As Boolean
    Dim wkRtn As Long: wkRtn = aRtn
    
    '終了位置が開始位置より小さい場合
    If wkRtn < aSttPos Then
        '長さ指定ありなら反映
        If aLength >= D_POS_START Then
            wkRtn = aSttPos + aLength - 1
        '長さ指定なしなら最大長反映
        Else
            wkRtn = aLenMax
        End If
    End If
    If wkRtn > aLenMax Then
        wkRtn = aLenMax
    End If
    
    If wkRtn >= D_POS_START Then
        aRtn = wkRtn
        PF_String_GetPosEndAdjust = True
    End If
End Function
~~~
## 文字列長調整
~~~
'------------------------------------------------------------------------------
' 文字列長調整
'------------------------------------------------------------------------------
Private Function PF_String_GetLengthAdjust( _
        ByRef aRtn As Long, _
        ByVal aLenMax As Long, _
        ByVal aSttPos As Long, _
        ByVal aEndPos As Long) As Boolean
    Dim wkRtn As Long: wkRtn = aRtn
    
    Dim wkLenMax As Long: wkLenMax = aLenMax - aSttPos + 1
    
    '文字列長さが範囲外の場合
    If wkRtn < D_POS_START Then
        '終了指定ありなら反映
        If aEndPos >= aSttPos Then
            wkRtn = aEndPos - aSttPos + 1
        '終了指定なしなら最大長反映
        Else
            wkRtn = wkLenMax
        End If
    End If
    If wkRtn > wkLenMax Then
        wkRtn = wkLenMax
    End If
    
    If wkRtn >= D_POS_START Then
        aRtn = wkRtn
        PF_String_GetLengthAdjust = True
    End If
End Function