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;
    }
    

  • 相关阅读:
    VMwareTools安装笔记
    Oracle常用命令(持续更新)
    window常用命令(持续更新)
    Oracle 中 sys和system帐号的区别
    决策树——排序算法的理论下界
    插入、选择、冒泡、梳排序性能比较
    插入、选择、冒泡排序的综述
    绝知此事要躬行之——插入排序
    Tree 和ls 的使用
    用户目录
  • 原文地址:https://www.cnblogs.com/yangykaifa/p/6879934.html
Copyright © 2011-2022 走看看