zoukankan      html  css  js  c++  java
  • 将C++的标识符转成OC的标识符

    3.将C++的标识符转成OC的标识符
     C++的标识符和OC一样由数字字母下划线组成。打头的不是数字。当标识符超过一个单词,
     C++採用全字母小写。单词间用下划线连接的书写规范,如:
     bei_jing
     OC採用除第一个单词外,其余单词首字母大写的书写规范。如:
    beiJing
     
     //传入C++标识符,返回OC标识符
     
     */
    + (NSString *)objcIdentifierFromCppIdentifier:(NSString *)idf
    //{
    //    //首先获取第0个字母
    //    NSMutableString * str1 = [NSMutableString stringWithFormat:@"%c",[idf characterAtIndex:0]];
    //    // 从第一个字母往后遍历。遇到‘_’符号后,取出‘_’后的字符将小写转换为大写,让i+1。否则,直接拼接
    //    for (NSInteger i = 1; i < idf.length; i++) {
    //        unichar ch = [idf characterAtIndex:i];
    //        if (ch == '_') {
    //            ch = [idf characterAtIndex:i+1];
    //            [str1 appendFormat:@"%c",ch-32];
    //            i++;
    //        } else {
    //            [str1 appendFormat:@"%c",ch];
    //        }
    //    }
    //    return str1;
    //}
    //{
    //    NSMutableString * str = [[NSMutableString alloc]init];
    //    for (NSInteger i = 0; i < idf.length; i++) {
    //        unichar ch = [idf characterAtIndex:i];
    //        if (ch == '_') {
    //            unichar ch = [idf characterAtIndex:i+1];
    //            [str appendFormat:@"%c",ch-32];
    //            i++;
    //        }
    //        else
    //        {
    //            [str appendFormat:@"%c",ch];
    //        }
    //    }
    //    return  str;
    //}
    {
        NSMutableString * str = [ NSMutableString stringWithFormat:@"%c",[idf characterAtIndex:0]];
                          for(NSInteger i = 1;i < idf.length;i++)
                          {
                              unichar ch = [idf characterAtIndex:i];
                              if(ch == '_')
                              {
                                  unichar ch = [idf characterAtIndex:i+1];
                                  [str appendFormat:@"%c",ch-32];
                                  i++;
                              }
                              else
                              {
                                  [str appendFormat:@"%c",ch];
                              }
                          }
        return str;
    }
    

  • 相关阅读:
    不务正业系列-浅谈《过气堡垒》,一个RTS玩家的视角
    [LeetCode] 54. Spiral Matrix
    [LeetCode] 40. Combination Sum II
    138. Copy List with Random Pointer
    310. Minimum Height Trees
    4. Median of Two Sorted Arrays
    153. Find Minimum in Rotated Sorted Array
    33. Search in Rotated Sorted Array
    35. Search Insert Position
    278. First Bad Version
  • 原文地址:https://www.cnblogs.com/yangykaifa/p/6879934.html
Copyright © 2011-2022 走看看