예제 #1
0
std::string NtbaUtil::hexAsciiDump(const unsigned char *data, size_t len, size_t bpl,
                                     const std::string delim)
{
    std::ostringstream out;
    size_t remain = len % bpl;
    size_t rows = len / bpl;

    for(size_t row = 0; row < rows; row++) {
        std::ostringstream hex;
        std::ostringstream ascii;
        /* add first hex value without a delim */
        hex << toHexString(data[row * bpl]);
        ascii << toAlpha(data[row * bpl]);
        /* add all col >= 1 values with prepended delim */
        for(size_t col = 1; col < bpl; col++ ) {
            hex << delim << toHexString(data[row * bpl + col]);
            ascii << toAlpha(data[row * bpl + col]);
        }
        /* prepend each line with the byte number */
        out << toSpacedHexString(row * bpl, 6);
        out << ": ";
        out << hex.str();
        out << "    ";
        out << ascii.str();
        out << std::endl;
    }
    if(remain > 0) {
        std::ostringstream hex;
        std::ostringstream ascii;
        /* add first hex value without a delim */
        hex << toHexString(data[rows * bpl]);
        ascii << toAlpha(data[rows * bpl]);
        /* add all col >= 1 values with prepended delim */
        for(size_t col = 1; col < remain; col++ ) {
            hex << delim << toHexString(data[rows * bpl + col]);
            ascii << toAlpha(data[rows * bpl + col]);
        }
        for(size_t col = remain; col < bpl; col++) {
            hex << "   ";
            ascii << " ";
        }
        out << toSpacedHexString(rows * bpl, 6);
        out << ": ";
        out << hex.str();
        out << "    ";
        out << ascii.str();
        out << std::endl;
    }
    return out.str();
}
예제 #2
0
파일: entity.cpp 프로젝트: lexdene/wolfenqt
static QVector<QImage> loadSoldierImages()
{
    QVector<QImage> images;
    for (int i = 1; i <= 40; ++i) {
        QImage image(QString("soldier/O%0.png").arg(i, 2, 10, QLatin1Char('0')));
        images << toAlpha(image.convertToFormat(QImage::Format_RGB32));
    }
    return images;
}
void morseCode(void) {
	std::string line = getLine("Enter a message: ");

	Map<std::string, std::string> symbolTable;
	constructSymbolTable(symbolTable);

	if(isalpha(line[0]))
		toMorse(line, symbolTable);
	else
		toAlpha(line, symbolTable);
}
예제 #4
0
파일: largestnum.c 프로젝트: aaa1616/Fairy
static void dfs(int dep, int maxdep, char *s, char *ret)
{
	if (dep == maxdep) {
		return;
	}
	int n = strlen(s);
	for (int i = 0; i < n; i++) {
		ret[dep] = toAlpha(s[dep])[i];
		ret[dep+ 1] = 0;
		dfs(dep + 1, maxdep, s, ret);
	}
}
예제 #5
0
파일: caesar1.c 프로젝트: dudren/CS50
int main(int argc, char* argv[])
{
    //stops the program if there are no command line arguments
    if (argc != 2)
    {
        printf("You must enter an argument.\n");
        return 1;
    }
    
    else
    {
        //key is changed to integer
        int k = atoi(argv[1]);
        printf("Enter a string you would like to encrypt with Caesar's cipher: \n");
        //gets the string from the user that we would like to encrypt
        char* s = GetString();
        char cipheredNum;
        int result;
        
        //loops through each char of the string
        for (int i = 0, n = strlen(s); i < n; i++)
        {
            //if the char is a capital or lowercase letter
            if (capital(s[i]) == 1 || lowerCase(s[i]) == 1)
            {
                //change to alphanumeric value, run the cipher, then change back to ascii
                int alphaNum = toAlpha(s[i]);
                cipheredNum = cipher(alphaNum, k);
                result = toAscii(cipheredNum);
            }
            //if the char is neither capital or lowercase, it stays the same
            else
                result = s[i];
            //prints the ciphered char before moving on to next char
            printf("%c", result);
        }
        printf("\n");
        return 0;
    }
}
bool QQuickStyledTextPrivate::parseTag(const QChar *&ch, const QString &textIn, QString &textOut, QTextCharFormat &format)
{
    skipSpace(ch);

    int tagStart = ch - textIn.constData();
    int tagLength = 0;
    while (!ch->isNull()) {
        if (*ch == greaterThan) {
            if (tagLength == 0)
                return false;
            QStringRef tag(&textIn, tagStart, tagLength);
            const QChar char0 = tag.at(0);
            if (char0 == QLatin1Char('b')) {
                if (tagLength == 1) {
                    format.setFontWeight(QFont::Bold);
                    return true;
                } else if (tagLength == 2 && tag.at(1) == QLatin1Char('r')) {
                    textOut.append(QChar(QChar::LineSeparator));
                    hasSpace = true;
                    prependSpace = false;
                    return false;
                }
            } else if (char0 == QLatin1Char('i')) {
                if (tagLength == 1) {
                    format.setFontItalic(true);
                    return true;
                }
            } else if (char0 == QLatin1Char('p')) {
                if (tagLength == 1) {
                    if (!hasNewLine)
                        textOut.append(QChar::LineSeparator);
                    hasSpace = true;
                    prependSpace = false;
                } else if (tag == QLatin1String("pre")) {
                    preFormat = true;
                    if (!hasNewLine)
                        textOut.append(QChar::LineSeparator);
                    format.setFontFamily(QString::fromLatin1("Courier New,courier"));
                    format.setFontFixedPitch(true);
                    return true;
                }
            } else if (char0 == QLatin1Char('u')) {
                if (tagLength == 1) {
                    format.setFontUnderline(true);
                    return true;
                } else if (tag == QLatin1String("ul")) {
                    List listItem;
                    listItem.level = 0;
                    listItem.type = Unordered;
                    listItem.format = Bullet;
                    listStack.push(listItem);
                }
            } else if (char0 == QLatin1Char('h') && tagLength == 2) {
                int level = tag.at(1).digitValue();
                if (level >= 1 && level <= 6) {
                    if (!hasNewLine)
                        textOut.append(QChar::LineSeparator);
                    hasSpace = true;
                    prependSpace = false;
                    setFontSize(7 - level, format);
                    format.setFontWeight(QFont::Bold);
                    return true;
                }
            } else if (tag == QLatin1String("strong")) {
                format.setFontWeight(QFont::Bold);
                return true;
            } else if (tag == QLatin1String("ol")) {
                List listItem;
                listItem.level = 0;
                listItem.type = Ordered;
                listItem.format = Decimal;
                listStack.push(listItem);
            } else if (tag == QLatin1String("li")) {
                if (!hasNewLine)
                    textOut.append(QChar(QChar::LineSeparator));
                if (!listStack.isEmpty()) {
                    int count = ++listStack.top().level;
                    for (int i = 0; i < listStack.size(); ++i)
                        textOut += QString(tabsize, QChar::Nbsp);
                    switch (listStack.top().format) {
                    case Decimal:
                        textOut += QString::number(count) % QLatin1Char('.');
                        break;
                    case LowerAlpha:
                        textOut += toAlpha(count, false) % QLatin1Char('.');
                        break;
                    case UpperAlpha:
                        textOut += toAlpha(count, true) % QLatin1Char('.');
                        break;
                    case LowerRoman:
                        textOut += toRoman(count, false) % QLatin1Char('.');
                        break;
                    case UpperRoman:
                        textOut += toRoman(count, true) % QLatin1Char('.');
                        break;
                    case Bullet:
                        textOut += bullet;
                        break;
                    case Disc:
                        textOut += disc;
                        break;
                    case Square:
                        textOut += square;
                        break;
                    }
                    textOut += QString(2, QChar::Nbsp);
                }
            }
            return false;
        } else if (ch->isSpace()) {
            // may have params.
            QStringRef tag(&textIn, tagStart, tagLength);
            if (tag == QLatin1String("font"))
                return parseFontAttributes(ch, textIn, format);
            if (tag == QLatin1String("ol")) {
                parseOrderedListAttributes(ch, textIn);
                return false; // doesn't modify format
            }
            if (tag == QLatin1String("ul")) {
                parseUnorderedListAttributes(ch, textIn);
                return false; // doesn't modify format
            }
            if (tag == QLatin1String("a")) {
                return parseAnchorAttributes(ch, textIn, format);
            }
            if (tag == QLatin1String("img")) {
                parseImageAttributes(ch, textIn, textOut);
                return false;
            }
            if (*ch == greaterThan || ch->isNull())
                continue;
        } else if (*ch != slash) {
            tagLength++;
        }
        ++ch;
    }
    return false;
}