AStyle — выравниваем код.

AStyle — отличный инструмент для выравнивания кода.

Имеет пять предопределенных стилей: ANSI, Linux, Java, GNU, K&R.

Манипулируя параметрами можно определить свой собственный. Работает с командной строки, и следовательно его можно встроить куда угодно.

Форматирует код написанный на C/C++/Java/CSharp . Проекту 100 лет в обед (начат в 1998 году), но его дополняют регулярно.

Может обрабатывать входной поток, может по одному файлу (сохраняя в случае необходимости оригинальный файл), пакетом в папке, плюс во всех подпапках, можно настраивать исключения и не форматировать всё подряд.

Резюме: в хозяйстве пригодится.

Варианты форматирования

Исходное форматирование:

using System;
using System.Collections;
 
public class MyClass
{
    public static void Main()
    {
 
        Console.WriteLine(checkSum(new int[] {9, 2}, 5));
        Console.WriteLine(checkSum(new int[] {5, 0}, 5));
        Console.WriteLine(checkSum(new int[] {2, 2}, 4));
        Console.WriteLine(checkSum(new int[] {5, 0, 2, 7 , 1, 9}, 5));
        Console.WriteLine(checkSum(new int[] {7, 8, 9, 7 , 8, 9}, 14));
     }
 
    public static bool checkSum(int[] numbers, int m)
    {
      BitArray myBits = new BitArray(m+1);
      foreach (int i in numbers)
      {
        if (i <= m)
        {
          myBits[m - i] = true;
          if (myBits[i])
          {
            return true;
          }
        }
      }
      return false;
 
    }
}

GNU Style:

using System;
using System.Collections;
 
public class MyClass
  {
    public static void Main()
    {
 
      Console.WriteLine(checkSum(new int[] {9, 2}, 5));
      Console.WriteLine(checkSum(new int[] {5, 0}, 5));
      Console.WriteLine(checkSum(new int[] {2, 2}, 4));
      Console.WriteLine(checkSum(new int[] {5, 0, 2, 7 , 1, 9}, 5));
      Console.WriteLine(checkSum(new int[] {7, 8, 9, 7 , 8, 9}, 14));
    }
 
    public static bool checkSum(int[] numbers, int m)
    {
      BitArray myBits = new BitArray(m+1);
      foreach (int i in numbers)
      {
        if (i <= m)
          {
            myBits[m - i] = true;
            if (myBits[i])
              {
                return true;
              }
          }
      }
      return false;
    }
  }

K&R Style:

using System;
using System.Collections;
 
public class MyClass {
    public static void Main() {
 
        Console.WriteLine(checkSum(new int[] {9, 2}, 5));
        Console.WriteLine(checkSum(new int[] {5, 0}, 5));
        Console.WriteLine(checkSum(new int[] {2, 2}, 4));
        Console.WriteLine(checkSum(new int[] {5, 0, 2, 7 , 1, 9}, 5));
        Console.WriteLine(checkSum(new int[] {7, 8, 9, 7 , 8, 9}, 14));
    }
 
    public static bool checkSum(int[] numbers, int m) {
        BitArray myBits = new BitArray(m+1);
        foreach (int i in numbers) {
            if (i <= m) {
                myBits[m - i] = true;
                if (myBits[i]) {
                    return true;
                }
            }
        }
        return false;
 
    }
}

ANSI Style:

using System;
using System.Collections;
 
public class MyClass
{
    public static void Main()
    {
 
        Console.WriteLine(checkSum(new int[] {9, 2}, 5));
        Console.WriteLine(checkSum(new int[] {5, 0}, 5));
        Console.WriteLine(checkSum(new int[] {2, 2}, 4));
        Console.WriteLine(checkSum(new int[] {5, 0, 2, 7 , 1, 9}, 5));
        Console.WriteLine(checkSum(new int[] {7, 8, 9, 7 , 8, 9}, 14));
    }
 
    public static bool checkSum(int[] numbers, int m)
    {
        BitArray myBits = new BitArray(m+1);
        foreach (int i in numbers)
        {
            if (i <= m)
            {
                myBits[m - i] = true;
                if (myBits[i])
                {
                    return true;
                }
            }
        }
        return false;
 
    }
}

Linux Style

using System;
using System.Collections;
 
public class MyClass
{
        public static void Main() {
 
                Console.WriteLine(checkSum(new int[] {9, 2}, 5));
                Console.WriteLine(checkSum(new int[] {5, 0}, 5));
                Console.WriteLine(checkSum(new int[] {2, 2}, 4));
                Console.WriteLine(checkSum(new int[] {5, 0, 2, 7 , 1, 9}, 5));
                Console.WriteLine(checkSum(new int[] {7, 8, 9, 7 , 8, 9}, 14));
        }
 
        public static bool checkSum(int[] numbers, int m) {
                BitArray myBits = new BitArray(m+1);
                foreach (int i in numbers) {
                        if (i <= m) {
                                myBits[m - i] = true;
                                if (myBits[i]) {
                                        return true;
                                }
                        }
                }
                return false;
        }
}

Java:

using System;
using System.Collections;
 
public class MyClass {
    public static void Main() {
 
        Console.WriteLine(checkSum(new int[] {9, 2}, 5));
        Console.WriteLine(checkSum(new int[] {5, 0}, 5));
        Console.WriteLine(checkSum(new int[] {2, 2}, 4));
        Console.WriteLine(checkSum(new int[] {5, 0, 2, 7 , 1, 9}, 5));
        Console.WriteLine(checkSum(new int[] {7, 8, 9, 7 , 8, 9}, 14));
    }
 
    public static bool checkSum(int[] numbers, int m) {
        BitArray myBits = new BitArray(m+1);
        foreach (int i in numbers) {
            if (i <= m) {
                myBits[m - i] = true;
                if (myBits[i]) {
                    return true;
                }
            }
        }
        return false;
    }
}

Tags: ,

Смотрите также:



  • http://www.flormag.ru Alexander

    спасибо за примеры кодов, очень интересно, в каждой системе своя стилистика