Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <QMessageBox>
- #include <iostream>
- #include <cstring>
- #include <cctype>
- #include <QDebug>
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- bool MainWindow::check_br(QString str){
- int count = 0;
- for (int i=0;i<str.size();i++) {
- if(str[i]=='(')
- count++;
- if(str[i]==')')
- count--;
- if(count<0)
- return false;
- }
- if(count!=0)
- return false;
- return true;
- }
- int MainWindow::checkname(char* str, int* pos){
- for (int i = 0; i < 3; i++) {
- if (!isalpha(str[*pos]))
- return 0;
- (*pos) += 2;
- }
- (*pos)--;
- if (str[*pos] != '=') return 0;
- (*pos)++;
- return (*pos);
- }
- bool MainWindow::param(char* str, int* pos){
- *pos = checkname(str, pos);
- if(*pos == 0){
- return false;
- }
- if (isdigit(str[*pos])){
- (*pos)+=2;
- if(isdigit(str[*pos]) != 0){
- *pos = *pos + 1;
- return true;
- }
- else
- {
- printf("F1");
- return false;
- }
- }
- else if(str[*pos] == '('){
- param(str + 1, pos);
- *pos = *pos + 1;
- if(str[*pos] != ')')
- {
- return false;
- }
- }
- else
- {
- printf("F2");
- return false;
- }
- }
- void MainWindow::on_pushButton_clicked()
- {
- int* pos = new int(0);
- *pos=0;
- ui->good->clear();
- ui->bad->clear();
- QString str = ui->lineEdit->text();
- char* temp = new char[str.length() + 1];
- strncpy(temp, str.toStdString().c_str(), str.length());
- temp[str.length()] = '\0';
- bool res = param(temp, pos);
- int ch = ')';
- char *ach;
- ach=strrchr (temp,ch);
- if(res) //&& check_br(str)
- ui->good->setText("НЕТ ОШИБКИ");
- else
- {
- ui->bad->setText("ОШИБКА");
- ui->good->clear();
- }
- /*if(ach != NULL)
- {
- if(temp[ach-temp+1] != '\0')
- {
- ui->bad->setText("ОШИБКА");
- ui->good->clear();
- }
- }
- else
- {
- if(*pos != str.length())
- {
- ui->bad->setText("ОШИБКА");
- ui->good->clear();
- }
- }*/
- int mas[100];
- int j = 0;
- int k;
- for(int i = 0; i<strlen(temp) - 1;i++)
- {
- if(temp[i]==',')
- {
- k = i+2;
- res =param(temp,&k);
- if(!res)
- {
- ui->bad->setText("ОШИБКА");
- ui->good->clear();
- }
- }
- }
- }
- void MainWindow::on_pushButton_2_clicked()
- {
- QMessageBox::about(this, "help", "Введите в поле строку, которую вы желаете проверить и нажмите кнопку проверки");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement