void CATextField::analyzeString(const char * text, int len) { std::string strLeft = m_sText.substr(0, m_iCurPos); std::string strRight = m_sText.substr(m_iCurPos, m_sText.size()); for (int i = 0; i < len; i++) { TextAttribute t; int iStrLen1 = getStringLength(strLeft); if (text[i] >= 0 && text[i] <= 127) { t.charSize = 1; strLeft += text[i]; } else { t.charSize = 3; strLeft += text[i++]; strLeft += text[i++]; strLeft += text[i]; } int iStrLen2 = getStringLength(strLeft); t.charlength = iStrLen2 - iStrLen1; m_vTextFiledChars.insert(m_vTextFiledChars.begin() + (getStringCharCount(strLeft)-1), t); m_iCurPos += t.charSize; } m_sText = strLeft + strRight; m_curSelCharRange = std::make_pair(m_iCurPos, m_iCurPos); }
void analyzeString(const char * text, int len) { std::string strLeft = m_sText.substr(0, m_iCurPos); std::string strRight = m_sText.substr(m_iCurPos, m_sText.size()); std::string cszNewText(text, len); std::u32string cszU32Text; StringUtils::UTF8ToUTF32(cszNewText, cszU32Text); for (int i = 0; i < cszU32Text.size(); i++) { std::u32string c; c += cszU32Text[i]; TextAttribute t; int iStrLen1 = getStringLength(strLeft); std::string str; StringUtils::UTF32ToUTF8(c, str); strLeft += str; t.charSize = str.size(); int iStrLen2 = getStringLength(strLeft); t.charlength = iStrLen2 - iStrLen1; m_vTextFiledChars.insert(m_vTextFiledChars.begin() + (getStringCharCount(strLeft) - 1), t); m_iCurPos += t.charSize; } m_sText = strLeft + strRight; m_curSelCharRange = std::make_pair(m_iCurPos, m_iCurPos); }
DRect getZZCRect(bool* l=0, bool* r=0) { int l1 = getStringLength(m_sText.substr(0, m_curSelCharRange.first)); int l2 = getStringLength(m_sText.substr(m_curSelCharRange.first, m_curSelCharRange.second - m_curSelCharRange.first)); int ld = getDtStrLength(); bool ll = (l1 + m_iString_o_length) >= 0; bool rr = (l1 + m_iString_o_length + l2 + ld) <= m_iLabelWidth; int dd = 0; if (ll && rr) { dd = l2; } else if (ll) { dd = m_iLabelWidth - (l1 + m_iString_o_length + ld); } else if (rr) { dd = l1 + m_iString_o_length + l2; } else dd = m_iLabelWidth; if (l != NULL) { *l = ll; } if (r != NULL) { *r = rr; } int y = (m_obContentSize.height - m_obRect.size.height) / 2; return DRect((ll ? (l1 + m_iString_o_length) : 0) + ld, y, dd, m_iFontHeight); }
std::vector<DRect> getZZCRect() { DSize size = getFrame().size; std::pair<int, int> t1 = getLineAndPos(m_curSelCharRange.first); std::pair<int, int> t2 = getLineAndPos(m_curSelCharRange.second); std::string s1 = m_szText.substr(t1.second, m_curSelCharRange.first - t1.second); if (!s1.empty() && s1[0] == '\n') s1.erase(0, 1); int l1 = getStringLength(s1); std::string s2 = m_szText.substr(t2.second, m_curSelCharRange.second - t2.second); if (!s2.empty() && s2[0] == '\n') s2.erase(0, 1); int l2 = getStringLength(s2); std::vector<DRect> vr; if (t1.first == t2.first) { vr.push_back(DRect(l1, m_iLineHeight*1.25f*t1.first, l2 - l1, m_iLineHeight)); } else { vr.push_back(DRect(l1, m_iLineHeight*1.25f*t1.first, size.width - l1, m_iLineHeight*1.25f)); int i = t1.first + 1; for (; i < t2.first; i++) { vr.push_back(DRect(0, m_iLineHeight*1.25f*i, size.width, m_iLineHeight*1.25f)); } vr.push_back(DRect(0, m_iLineHeight*1.25f*i, l2, m_iLineHeight)); } return vr; }
void ATOM_Edit::deleteString( size_t start,size_t end ) { // 只读情况,不允许输入 if(EDITTYPE_READONLY & _editType) { return; } int s,t; s = min(start,end); t = max(start,end); ATOM_STRING str = ATOM_Wide2Ansi (_string.c_str(), _string.size()); if(t > _string.size()) { end = ATOM_STRING::npos; } str.erase(s,t-s); _string = ATOM_Ansi2Wide(str.c_str(), strlen(str.c_str())); calcTextLayout (); _textDirty = false; if(_cursor<0) { _cursor = 0; } if(_cursor > getStringLength()) { _cursor = getStringLength(); } _cusorOldPosition = _cusorNewPosition; ATOM_EditTextChangedEvent event(getId(), _text->getString()); _parent->handleEvent(&event); }
CCRect CATextField::getZZCRect(bool* l, bool* r) { int l1 = getStringLength(m_sText.substr(0, m_curSelCharRange.first)); int l2 = getStringLength(m_sText.substr(m_curSelCharRange.first, m_curSelCharRange.second-m_curSelCharRange.first)); bool ll = (l1 + m_iString_left_offX) >= 0; bool rr = (l1 + m_iString_left_offX + l2) <= m_iLabelWidth; int dd = 0; if (ll && rr) { dd = l2; } else if (ll) { dd = m_iLabelWidth - (l1 + m_iString_left_offX); } else if (rr) { dd = l1 + m_iString_left_offX + l2; } else dd = m_iLabelWidth; if (l != NULL) { *l = ll; } if (r != NULL) { *r = rr; } return CCRect((ll ? (l1 + m_iString_left_offX) : 0) + m_iHoriMargins, m_iVertMargins, dd, m_iFontHeight); }
int getMaxStringLength(char string[][81], const int number_of_string) { int max = 0; for (int i = 0; i < number_of_string; ++i) if (getStringLength(string[i]) > max) max = getStringLength(string[i]); return max; }
void test_generate_base85_password () { char* password = generatePassword(12, BASE85); int i=0; for(i=0;i<getStringLength(password);i++) CU_ASSERT_TRUE(containsChar(base85,password[i])); CU_ASSERT_EQUAL(getStringLength(password),12); }
static bool MutableString_equals (const void * const _self, const void *const _other) { const struct String *self = _self; const struct String *other = _other; int result = ( _self == _other ); if ( ! result && (getStringLength(self) == getStringLength(other)) && self->text && other->text) result = (strcmp(self->text, other->text) == 0); return result; }
void test_generate_base64_password () { char* password = generatePassword(12, BASE64); int i=0; for(i=0;i<getStringLength(password);i++) CU_ASSERT_TRUE(containsChar(base64,password[i])); printf("len: %d", getStringLength(password)); CU_ASSERT_EQUAL(getStringLength(password),12); }
//----------------------------------------------------------------------------// String IconvStringTranscoder::stringFromUTF16(const uint16* input) const { #if CEGUI_STRING_CLASS == CEGUI_STRING_CLASS_UNICODE IconvHelper ich("UTF-8", "UTF-16"); return iconvTranscode<String, utf8>( ich, reinterpret_cast<const char*>(input), getStringLength(input) * sizeof(uint16)); #else IconvHelper ich("WCHAR_T", "UTF-16"); return stringFromStdWString(iconvTranscode<std::wstring, wchar_t>( ich, reinterpret_cast<const char*>(input), getStringLength(input))); #endif }
static void MutableString_appendString(void *const _self, const void *const _other) { struct MutableString *self = _self; struct String *stringSelf = _self; const struct MutableString *other = _other; const char *otherText = getStringText(other); UInteger selfLength = getStringLength(self); UInteger otherLength = getStringLength(other); if ( __ensureCapacity(self, selfLength + otherLength + 1) == -1 ) { errno = ENOMEM; return; }; char *selfText = (char *)getStringText(self); strncat(selfText, otherText, otherLength); stringSelf->length += otherLength; }
int getIndex(char *c) { int len = getStringLength(c); //printf("%s %s\n", "string ", c); if(*(c + len - 1) =='\n') { len--; } int counter = 0; int currentIndex = len - 1; while(*(c + currentIndex) != ' ') { currentIndex--; counter++; } currentIndex++; //printf("%s %d\n", "size of countr ", counter); char *substring = (char *)malloc((counter + 1) * sizeof(char)); for(int i = 0; i < counter; i++) { *(substring + i) = *(c + currentIndex + i); } *(substring + counter) = '\0'; //printf("%s %s\n", "substring", substring); int resultIndex = convertStringToInt(substring); //printf("%d\n", resultIndex); free(substring); return resultIndex; }
void CATextField::adjustCursorMoveForward() { this->updateImage(); m_iString_l_length = getStringLength(m_sText.substr(0, m_iCurPos)); m_iString_r_length = m_cImageSize.width - m_iString_l_length; if (m_iString_l_length + m_iString_left_offX > m_iLabelWidth) { m_iString_left_offX = m_iLabelWidth - m_iString_l_length; } CCRect r = CCRectMake(0, 0, m_cImageSize.width, m_cImageSize.height); r.origin.x = -m_iString_left_offX; r.size.width = getStringViewLength(); this->setImageRect(r); if (m_nInputType == KEY_BOARD_INPUT_PASSWORD) { //float mPmarkWidth = MIN(m_obContentSize.width, getCursorX()); m_pCursorMark->setCenterOrigin(CCPoint(this->getImageRect().size.width + m_iHoriMargins, m_obContentSize.height / 2)); } else { float mPmarkWidth = MIN(m_obContentSize.width, getCursorX()); m_pCursorMark->setCenterOrigin(CCPoint(mPmarkWidth + m_iHoriMargins, m_obContentSize.height / 2)); } }
/** Returns the number of bytes necessary to store a string vector. * \param vs std::vector<std::string> */ int STVRMessage::getStringVectorLength(const std::vector<std::string>& vs) { int len=getShortLength(); for(unsigned int i=0; i<vs.size(); i++) len += getStringLength(vs[i]); return len; } // getStringVectorLength
void CATextView::calculateSelChars(const CCPoint& point, int& l, int& r, int& p) { float y = point.y + m_pContainerView->getContentOffset().y; int iCurLine = getCurrentByPointY(y); int iHalfCharSize = 0; int iStartPos = 0; if (!m_vLinesTextView.empty()) { p = iStartPos = m_vLinesTextView[iCurLine].iStartCharPos; std::vector<TextAttribute>& v = m_vLinesTextView[iCurLine].TextAttrVect; for (int i = 0, iStringLeftX = 0; i < v.size(); i++) { TextAttribute& t = v[i]; if (point.x >= iStringLeftX - iHalfCharSize && point.x < iStringLeftX + t.charlength / 2) { break; } iStringLeftX += t.charlength; p += t.charSize; iHalfCharSize = t.charlength / 2; } } std::string s = m_szText.substr(iStartPos, p - iStartPos); if (!s.empty() && s[0] == '\n') { s.erase(0, 1); } l = iCurLine; r = getStringLength(s); }
int main(void) { int i, j; char string[5][81]; #if 0 /* No use if not get use of fgets */ int max_length_of_string; puts("Please enter the max length of the string(<81):"); scanf("%d", &max_length_of_string); if (max_length_of_string >= 81 || max_length_of_string <= 0) { puts("Error, now exit."); return 1; } #endif puts("Please enter 5 strings, one line one string:"); for (i = 0; i < 5; ++i) gets(string[i]); for (i = 0; i < 5; ++i) if (getStringLength(string[i]) < getMaxStringLength(string, 5)) fillStringByBlanks(string[i], getMaxStringLength(string, 5)); for (i = 0; i < 5; ++i) { for (j = 0; string[i][j]; ++j) putchar(string[i][j]); putchar('\n'); } return 0; }
document_attachment_ptr Document::getAttachment(const char* name, bool includeBody) { document_attachment_ptr attachment; auto attachmentsObj = obj_->getObject("_attachments", false); if (!!attachmentsObj) { auto attachmentObj = attachmentsObj->getObject(name, false); if (!!attachmentObj) { auto contentType = attachmentObj->getString("content_type"); auto digest = attachmentObj->getString("digest"); if (includeBody) { auto encodedData = attachmentObj->getString("data"); auto encodedDataSize = attachmentObj->getStringLength("data"); auto data = Base64Helper::Decode(encodedData, encodedDataSize); attachment = DocumentAttachment::Create(name, contentType, digest, std::move(data)); } else { int lengthIndex = -1; auto size = attachmentObj->getType("length", lengthIndex) == rs::scriptobject::ScriptObjectType::UInt32 ? attachmentObj->getUInt32(lengthIndex) : attachmentObj->getUInt64(lengthIndex); attachment = DocumentAttachment::Create(name, contentType, digest, Base64Helper::buffer_type{}, size); } } } return attachment; }
std::vector<document_attachment_ptr> Document::getAttachments() { std::vector<document_attachment_ptr> attachments; auto attachmentsObj = obj_->getObject("_attachments", false); if (!!attachmentsObj) { auto count = attachmentsObj->getCount(); attachments.reserve(count); for (decltype(count) i = 0; i < count; ++i) { auto type = attachmentsObj->getType(i); if (type == rs::scriptobject::ScriptObjectType::Object) { auto name = attachmentsObj->getName(i); auto attachmentObj = attachmentsObj->getObject(i); auto contentType = attachmentObj->getString("content_type"); auto digest = attachmentObj->getString("digest"); auto encodedData = attachmentObj->getString("data"); auto encodedDataSize = attachmentObj->getStringLength("data"); auto data = Base64Helper::Decode(encodedData, encodedDataSize); auto attachment = DocumentAttachment::Create(name, contentType, digest, std::move(data)); attachments.push_back(attachment); } } } return attachments; }
void ATOM_Edit::setCursor(int cursor, bool select) { ATOM_STACK_TRACE(ATOM_Edit::setCursor); size_t length = getStringLength(); if(select) { if(_selectStart < 0 || _selectStart > length) { _selectStart = _cursor; } } else { _selectStart = -1; } if(_cursor == _startPosition && cursor < _cursor) { _startPosition = cursor; } int oldPosition = _cursor; _cursor = cursor; if(_cursor<0) { _cursor = 0; } if(_cursor > length) { _cursor = length; } _textDirty = true; }
/** Constructor, takes the name of the kart name and the host id. * \param kart_name Name of the kart. * \param host_id Id of the host who selected this character. */ CharacterConfirmMessage(const std::string &kart_name, int host_id) : Message(Message::MT_CHARACTER_CONFIRM) { allocate(getStringLength(kart_name) + getCharLength()); addString(kart_name); addChar(host_id); } // CharacterConfirmMessage
void Decimal::getStringX(size32_t & length, char * & buffer) const { unsigned len = getStringLength(); buffer = (char *)malloc(len); unsigned written = doGetString(buffer); assertex(len == written); length = len; }
void Label::draw() { const double size = _height / 1.9; const double space = (_width - getStringLength(size, _text)) / 2.; glTranslated(space, (_height - size) / 2., 0.); drawString(size, _text); glTranslated(-space, -(_height - size) / 2., 0.); }
char * Decimal::getCString() const { unsigned len = getStringLength(); char * buffer = (char *)malloc(len+1); unsigned written = doGetString(buffer); assertex(len == written); buffer[len] = 0; return buffer; }
void test_twofish_decrypt_encrypt_wrong_size() { char *key = "ldlelslelslelslslflellalelslssl"; char *plainText = "ldlelslelslelslslflelslalelslsslldlelslelslelslslflelslallslssl"; enum EncryptionAlgorithm algorithm = TWOFISH; initCryptographyModule(); int plainTextSize = getStringLength(plainText); char *cipherText = encryptString(plainText,plainTextSize, key, algorithm); CU_ASSERT_EQUAL(cipherText, NULL); freeCryptographyModuleMemory(); }
void fillStringByBlanks(char* string, const int max_length_of_string) { int i = max_length_of_string; int j = getStringLength(string); while (j >= 0) string[i--] = string[j--]; while (i >= 0) string[i--] = ' '; return; }
int main(int argc, char **argv) { char *inputNumber = argv[1]; char *srcBase = argv[2]; char *destBase = argv[3]; int srcBaseInt = convertCharNumberToInt(srcBase); int destBaseInt = convertCharNumberToInt(destBase); long inputNumberLong = convertToDecimal(inputNumber, srcBaseInt,0,getStringLength(inputNumber)); printf("Conversion of %s base %s to base %s is : %s\n",inputNumber, srcBase, destBase, convertDecimalToBase(inputNumberLong, destBaseInt)); return 0; }
int convertCharNumberToInt(char *number) { int i; int place = 1; int sum = 0; for (i = getStringLength(number) - 1; number[i]; i--) { int temp = convertCharToNumber(number[i]); sum = sum + (temp * place); place = place * 10; } return sum; }
void test_twofish_decrypt_encrypt_null() { char *key = NULL; char *plainText = NULL; enum EncryptionAlgorithm algorithm = TWOFISH; initCryptographyModule(); int plainTextSize = getStringLength(plainText); char *cipherText = encryptString(plainText,plainTextSize, key, algorithm); char *plainText2 = decryptString(cipherText,plainTextSize, key, algorithm); CU_ASSERT_EQUAL(plainText, NULL); CU_ASSERT_EQUAL(plainText2, NULL); freeCryptographyModuleMemory(); }
char* rotateString(char string[]){ int length = getStringLength(string); char last = string[0]; int i; for(i = 0; i<length-1; i++){ string[i] = string[i+1]; } string[length-1] = last; return string; }