def smethod_0(string_0):
     stringBuilder = StringBuilder(string_0)
     num = 0
     tempChrList = String.ToCharArray(string_0)
     while (num < stringBuilder.Length):
         if (tempChrList[num] == '\r'):
             if (num >= stringBuilder.Length - 1
                     or stringBuilder[num + 1] != '\n'):
                 num += 1
                 stringBuilder.Insert(num, '\n')
             else:
                 num = num + 2
                 continue
         num += 1
     return stringBuilder.ToString()
示例#2
0
    def ToString(self, formatStr=None):
        if formatStr == None:
            return self.ToString("G")
        num = 0.0
        num1 = 0.0
        num2 = 0.0
        if (self.IsNaN):
            return ""
        if (formatStr == None or formatStr == ""):
            formatStr = self.defaultformatStr
        # if (provider == null)
        # {
        #     provider = CultureInfo.CurrentCulture;
        # }
        # s = QString(45)
        # s.toUpper()

        if isinstance(formatStr, QString):
            formatStr = formatStr.toUpper()
        else:
            formatStr = formatStr.upper()
        if (formatStr == "G"):
            formatStr = self.defaultformatStr.upper()
        stringBuilder = StringBuilder()
        strS = None
        str1 = None
        str2 = None
        num3 = 0
        num4 = 0
        num5 = 0
        length = -1
        length1 = -1
        length2 = -1
        num6 = 0
        while (len(formatStr) > num6):
            chr = formatStr[num6]
            if (chr == 'D'):
                if (strS != None):
                    return None
                    # throw new ArgumentException("formatStr");
                strS = "0"
                num6 += 1
                flag = False
                while (len(formatStr) > num6):
                    if (formatStr[num6] != 'D'):
                        if (formatStr[num6] != '.'):
                            break
                        strS = String.Concat([strS, "."])
                        flag = True
                        num6 += 1
                    else:
                        strS = String.Concat([strS, "0"])
                        if (flag):
                            num3 += 1
                        num6 += 1
                length = stringBuilder.Length
            elif (chr == 'M'):
                if (strS == None):
                    return None
                    # throw new ArgumentException("formatStr");
                if (str1 != None):
                    return None
                    # throw new ArgumentException("formatStr");
                str1 = "0"
                num6 += 1
                flag1 = False
                while (len(formatStr) > num6):
                    if (formatStr[num6] != 'M'):
                        if (formatStr[num6] != '.'):
                            break
                        str1 = String.Concat([str1, "."])
                        flag1 = True
                        num6 += 1
                    else:
                        str1 = String.Concat([str1, "0"])
                        if (flag1):
                            num4 += 1
                        num6 += 1
                length1 = stringBuilder.Length
            elif (chr == 'S'):
                if (strS == None):
                    return None
                    # throw new ArgumentException("formatStr");
                if (str1 == None):
                    return None
                    # throw new ArgumentException("formatStr");
                if (str2 != None):
                    return None
                    # throw new ArgumentException("formatStr");
                str2 = "0"
                num6 += 1
                flag2 = False
                while (len(formatStr) > num6):
                    if (formatStr[num6] != 'S'):
                        if (formatStr[num6] != '.'):
                            break
                        str2 = String.Concat([str2, "."])
                        flag2 = True
                        num6 += 1
                    else:
                        str2 = String.Concat([str2, "0"])
                        if (flag2):
                            num5 += 1
                        num6 += 1
                length2 = stringBuilder.Length
            elif (chr == 'H'):
                if (self.type == DegreesType.Latitude):
                    if (self.value >= 0):
                        stringBuilder.Append("N")
                    else:
                        stringBuilder.Append("S")
                elif (self.type == DegreesType.Longitude
                      or self.type == DegreesType.Variation):
                    if (self.value >= 0):
                        stringBuilder.Append("E")
                    else:
                        stringBuilder.Append("W")
                num6 += 1
            elif (chr != '-'):
                stringBuilder.Append(chr)
                num6 += 1
            else:
                if (self.value < 0):
                    stringBuilder.Append("-")
                num6 += 1
        if (str2 != None):
            num = math.fabs(self.value) if (not math.isinf(self.value)) else 0
            num7 = math.trunc(num)
            num8 = (num - num7) * 60
            num9 = math.trunc(num8)
            num10 = round((num8 - num9) * 60, num5)
            if (num10 >= 60):
                num10 = num10 - 60
                num9 = num9 + 1
            if (num9 >= 60):
                num9 = num9 - 60
                num7 = num7 + 1

            stringBuilder.Insert(length2, String.Number2String(num10, str2))
            stringBuilder.Insert(length1, String.Number2String(num9, str1))
            stringBuilder.Insert(length, String.Number2String(num7, strS))
        elif (str1 == None):
            if (strS == None):
                return None
                # throw new ArgumentException("formatStr");
            num2 = math.fabs(self.value) if (not math.isinf(self.value)) else 0
            num11 = round(num2, num3)
            stringBuilder.Insert(length, String.Number2String(num11, strS))
        else:
            num1 = math.fabs(self.value) if (not math.isinf(self.value)) else 0
            num12 = math.trunc(num1)
            num13 = round((num1 - num12) * 60, num4)
            if (num13 >= 60):
                num13 = num13 - 60
                num12 = num12 + 1
            stringBuilder.Insert(length1, String.Number2String(num13, str1))
            stringBuilder.Insert(length, String.Number2String(num12, strS))

        return stringBuilder.ToString()