Пример #1
0
        /// <summary>
        /// Converts the phrase to specified convention.
        /// </summary>
        /// <param name="phrase"></param>
        /// <param name="pattern">The cases.</param>
        /// <returns>string</returns>
        static string ConvertCaseString(string phrase, RenameCasePattern pattern)
        {
            var splittedPhrase = phrase.Split(' ', '-', '.');
            var sb             = new StringBuilder();

            switch (pattern)
            {
            case RenameCasePattern.LowerCamelCase:
                sb.Append(splittedPhrase[0].ToLower());
                splittedPhrase[0] = string.Empty;
                break;

            case RenameCasePattern.UpperCamelCase:
                sb = new StringBuilder();
                break;
            }

            foreach (var s in splittedPhrase)
            {
                var splittedPhraseChars = s.ToCharArray();
                if (splittedPhraseChars.Length > 0)
                {
                    var str = new String(splittedPhraseChars[0], 1);
                    splittedPhraseChars[0] = (str.ToUpper().ToCharArray())[0];
                }
                sb.Append(new String(splittedPhraseChars));
            }
            return(sb.ToString());
        }
Пример #2
0
        /// <summary>
        /// Converts the phrase to specified convention.
        /// </summary>
        /// <param name="phrase"></param>
        /// <param name="pattern">The cases.</param>
        /// <returns>string</returns>
        static string ConvertCaseString(string phrase, RenameCasePattern pattern)
        {
            var splittedPhrase = phrase.Split(' ', '-', '.');
            var sb = new StringBuilder();

            switch (pattern)
            {
                case RenameCasePattern.LowerCamelCase:
                    sb.Append(splittedPhrase[0].ToLower());
                    splittedPhrase[0] = string.Empty;
                    break;
                case RenameCasePattern.UpperCamelCase:
                    sb = new StringBuilder();
                    break;
            }

            foreach (var s in splittedPhrase)
            {
                var splittedPhraseChars = s.ToCharArray();
                if (splittedPhraseChars.Length > 0)
                {
                    var str = new String(splittedPhraseChars[0], 1);
                    splittedPhraseChars[0] = (str.ToUpper().ToCharArray())[0];
                }
                sb.Append(new String(splittedPhraseChars));
            }
            return sb.ToString();
        }
Пример #3
0
        /// <summary>
        /// Converts the phrase to specified convention.
        /// </summary>
        /// <param name="decl"></param>
        /// <param name="pattern">The cases.</param>
        /// <returns>string</returns>
        public static string ConvertCaseString(Declaration decl, RenameCasePattern pattern)
        {
            if (decl.Name.All(c => !char.IsLetter(c)))
            {
                return(decl.Name);
            }

            var typedef = decl as TypedefDecl;

            if (typedef != null && typedef.IsSynthetized)
            {
                return(decl.Name);
            }

            var property = decl as Property;

            if (property != null && property.GetMethod != null &&
                property.GetMethod.SynthKind == FunctionSynthKind.InterfaceInstance)
            {
                return(decl.Name);
            }

            var sb = new StringBuilder(decl.Name);

            // check if it's been renamed to avoid a keyword
            if (sb[0] == '@' || sb[0] == '$')
            {
                sb.Remove(0, 1);
            }

            RemoveUnderscores(sb);

            var @class = decl as Class;

            switch (pattern)
            {
            case RenameCasePattern.UpperCamelCase:
                // ensure separation in enum items by not ending up with more capitals in a row than before
                if (sb.Length == 1 || !char.IsUpper(sb[1]) || !(decl is Enumeration.Item))
                {
                    sb[0] = char.ToUpperInvariant(sb[0]);
                }
                if (@class != null && @class.Type == ClassType.Interface)
                {
                    sb[1] = char.ToUpperInvariant(sb[1]);
                }
                break;

            case RenameCasePattern.LowerCamelCase:
                sb[0] = char.ToLowerInvariant(sb[0]);
                if (@class != null && @class.Type == ClassType.Interface)
                {
                    sb[1] = char.ToLowerInvariant(sb[1]);
                }
                break;
            }

            return(sb.ToString());
        }
Пример #4
0
 public static void RenameDeclsCase(this PassBuilder <TranslationUnitPass> builder,
                                    RenameTargets targets, RenameCasePattern pattern)
 {
     builder.AddPass(new CaseRenamePass(targets, pattern));
 }
Пример #5
0
        /// <summary>
        /// Converts the phrase to specified convention.
        /// </summary>
        /// <param name="decl"></param>
        /// <param name="pattern">The cases.</param>
        /// <returns>string</returns>
        static string ConvertCaseString(Declaration decl, RenameCasePattern pattern)
        {
            if (decl.Name.All(c => !char.IsLetter(c)))
            {
                return(decl.Name);
            }

            var typedef = decl as TypedefDecl;

            if (typedef != null && typedef.IsSynthetized)
            {
                return(decl.Name);
            }

            var property = decl as Property;

            if (property != null && property.GetMethod != null &&
                property.GetMethod.SynthKind == FunctionSynthKind.InterfaceInstance)
            {
                return(decl.Name);
            }

            var sb = new StringBuilder(decl.Name);

            // check if it's been renamed to avoid a keyword
            if (sb[0] == '@')
            {
                sb.Remove(0, 1);
            }

            for (int i = sb.Length - 1; i >= 0; i--)
            {
                if (sb[i] == '_' && i < sb.Length - 1)
                {
                    sb[i + 1] = char.ToUpperInvariant(sb[i + 1]);
                    sb.Remove(i, 1);
                }
            }

            var @class = decl as Class;

            switch (pattern)
            {
            case RenameCasePattern.UpperCamelCase:
                sb[0] = char.ToUpperInvariant(sb[0]);
                if (@class != null && @class.Type == ClassType.Interface)
                {
                    sb[1] = char.ToUpperInvariant(sb[1]);
                }
                break;

            case RenameCasePattern.LowerCamelCase:
                sb[0] = char.ToLowerInvariant(sb[0]);
                if (@class != null && @class.Type == ClassType.Interface)
                {
                    sb[1] = char.ToLowerInvariant(sb[1]);
                }
                break;
            }

            return(sb.ToString());
        }
Пример #6
0
 public CaseRenamePass(RenameTargets targets, RenameCasePattern pattern)
     : base(targets)
 {
     Pattern = pattern;
 }
Пример #7
0
 public CaseRenamePass(RenameTargets targets, RenameCasePattern pattern)
     : base(targets)
 {
     Pattern = pattern;
 }
Пример #8
0
 public static void RenameDeclsCase(this PassBuilder<TranslationUnitPass> builder, 
     RenameTargets targets, RenameCasePattern pattern)
 {
     builder.AddPass(new CaseRenamePass(targets, pattern));
 }