示例#1
0
int BLI_uniquename_cb(int (*unique_check)(void *, const char *), void *arg, const char defname[], char delim, char *name, short name_len)
{
	if(name[0] == '\0') {
		BLI_strncpy(name, defname, name_len);
	}

	if(unique_check(arg, name)) {
		char	tempname[UNIQUE_NAME_MAX];
		char	left[UNIQUE_NAME_MAX];
		int		number;
		int		len= BLI_split_name_num(left, &number, name, delim);
		do {
			int newlen= BLI_snprintf(tempname, name_len, "%s%c%03d", left, delim, ++number);
			if(newlen >= name_len) {
				len -= ((newlen + 1) - name_len);
				if(len < 0) len= number= 0;
				left[len]= '\0';
			}
		} while(unique_check(arg, tempname));

		BLI_strncpy(name, tempname, name_len);
		
		return 1;
	}
	
	return 0;
}
示例#2
0
int BLI_uniquename_cb(int (*unique_check)(void *, const char *), void *arg, const char defname[], char delim, char *name, short name_len)
{
	if (name[0] == '\0') {
		BLI_strncpy(name, defname, name_len);
	}

	if (unique_check(arg, name)) {
		char numstr[16];
		char tempname[UNIQUE_NAME_MAX];
		char left[UNIQUE_NAME_MAX];
		int number;
		int len = BLI_split_name_num(left, &number, name, delim);
		do {
			int numlen = BLI_snprintf(numstr, sizeof(numstr), "%c%03d", delim, ++number);

			/* highly unlikely the string only has enough room for the number
			 * but support anyway */
			if ((len == 0) || (numlen >= name_len)) {
				/* number is know not to be utf-8 */
				BLI_strncpy(tempname, numstr, name_len);
			}
			else {
				char *tempname_buf;
				tempname[0] = '\0';
				tempname_buf = BLI_strncat_utf8(tempname, left, name_len - numlen);
				memcpy(tempname_buf, numstr, numlen + 1);
			}
		} while (unique_check(arg, tempname));

		BLI_strncpy(name, tempname, name_len);
		
		return 1;
	}
	
	return 0;
}
示例#3
0
QStringList cube_list(QString txt, int *error)
{
        QStringList cube_list;
        int expected_color_count = 9;
        int expected_cube_count = 26;

        QString help = "";
        int one_color_dice_count = 0, two_color_dice_count = 0, three_color_dice_count = 0;
        for(int i = 0; i < expected_cube_count; i++)
        {
            txt.remove(txt.indexOf("#"), txt.indexOf('\n')+1);
            help = txt.mid(0, txt.indexOf("\n\n"));
            cube_list << help;
            txt.remove(0, txt.indexOf("#"));

            if(help.count('\n') == 0)
            {
                one_color_dice_count++;
            }
            else if(help.count('\n') == 1)
            {

                QString color_1, color_2;
                color_1 = help.section('\n', 0, 0);
                color_2 = help.section('\n', 1, 1);
                if(color_1 == color_2)
                {
                    //Two of same colors on one cube
                    *error = 701+i;
                    return cube_list;
                }

                two_color_dice_count++;

            }
            else if(help.count('\n') == 2)
            {
                QString color_1, color_2, color_3;
                color_1 = help.section('\n', 0, 0);
                color_2 = help.section('\n', 1, 1);
                color_3 = help.section('\n', 2, 2);
                if(color_1 == color_2 || color_1 == color_3 || color_2 == color_3)
                {
                    //Two or more of same colors on one cube
                    *error = 801+i;
                    return cube_list;
                }

                three_color_dice_count++;
            }
            else
            {
                //Incorrect input file.
                *error = 901+i;
                return cube_list;
            }
        }

        if(cube_list.filter("blue").count() != expected_color_count || cube_list.filter("red").count() != expected_color_count ||
           cube_list.filter("green").count() != expected_color_count || cube_list.filter("white").count() != expected_color_count ||
           cube_list.filter("yellow").count() != expected_color_count || cube_list.filter("orange").count() != expected_color_count)
        {
            // Wrong amount of colors
            *error = 6;
            return cube_list;
        }

        if(one_color_dice_count != 6 || two_color_dice_count != 12 || three_color_dice_count !=8)
        {
            //Wrong amount of cubes
            *error = 4;
            return cube_list;
        }
        else
        {
            cube_list = cube_list.filter("\n");
        }

        return unique_check(cube_list, error);
}