日期:2010-03-23  浏览次数:20562 次

#Region "由拼音到拼音"
    Public Shared Function GetPyToPy(ByVal PYStr As String, _
                                     Optional ByVal IsComp As Boolean = False) As String
        If PYStr.Length = 0 Then Exit Function

        mIsCompelled = IsComp

        Dim toneSite As Integer
        Dim toneValue As Integer
        Dim toneChar As Char

        toneSite = GetToneSite(PYStr)
        If toneSite = -1 Then
            Return PYStr
        ElseIf toneSite < -1 Then
            Exit Function
        End If

        toneValue = GetToneValue(PYStr, toneSite)
        If toneValue = -1 Then Exit Function

        If mIsCompelled Then
            toneChar = GetToneChar(PYStr, toneSite - 1)
        Else
            toneChar = GetToneChar(PYStr)
        End If
        If Not isPyChar(toneChar) Then Exit Function
        Return Conversion(PYStr, toneSite, toneValue, toneChar)

    End Function
    '返回标明声调数值的位置
    Private Shared Function GetToneSite(ByVal pyStr As String) As Integer
        If pyStr.Length = 0 Then Exit Function
        Dim i As Integer, j As Integer = 0
        '检查字串中有几个数字
        For i = 0 To pyStr.Length - 1
            If Char.IsNumber(pyStr.Chars(i)) Then
                j += 1
            End If
        Next
        If j = 0 Then       '没有数字,即没有标明声调的数值
            Return -1
        ElseIf j = 1 Then   '有一个数字,合法
            For i = 0 To pyStr.Length - 1
                If Char.IsNumber(pyStr.Chars(i)) Then
                    Return i
                End If
            Next
        Else                '有多个数