Quick actions

cmd+k|ctrl+k

Navigation

Languages

CheckBrackets

Snippet info

Language

Csharp

Visibility

public

Author

sivan606

Created

2019-05-30T02:00:23Z

Updated

2019-05-30T02:00:23Z

using System;
using System.Collections.Generic;
using System.IO;

class CheckBrackets {
    static void Main(string[] args) {
        FileStream fs_in = new FileStream(args[0], FileMode.Open, FileAccess.Read);
		string bracket_types = args[1].Replace("\"", "").Replace("'", "");
		if (Array.Exists(args, arg => arg == "--quotes")));
		Stack<char> stack = new Stack<char>;
        StreamReader sr_in = new StreamReader(fs_in);
		string contents = sr_dict.ReadToEnd();
		sr_in.Close();
        bool flag = false, quotes1_open = false, quotes2_open = false;
        for (int i = 0; i < contents.Length; ++i)
		{
			switch (line[i])
			{
				case '\'': 	quotes1_open = !quotes1_open;
							break;
				case '"': 	quotes2_open = !quotes2_open;
							break;
				default:	if (!quotes1_open && !quotes2_open && !CheckCharacter(stack, bracket_types, line[i]))
							{
								flag = true;
								break;
							}
			}
		}
        if (flag)
            Console.WriteLine("WARNING");
        else
            Console.WriteLine("OK");
    }
	
	static bool CheckCharacter(ref Stack<char> stack, string bracket_types, char ch)
	{
		int ind = bracket_types.indexOf(ch);
		if (ch == '"' || ch )
		if (ind == -1)
			return true;
		if ((ind % 2) && stack.Pop() != bracket_types[ind + 1])
			return false;
		stack.Push(ch);
		return true;
	}
}
INFO