void String::remove(unsigned position, int lengthToRemove) { if (lengthToRemove <= 0) return; if (position >= length()) return; if (static_cast<unsigned>(lengthToRemove) > length() - position) lengthToRemove = length() - position; StringBuffer buffer(length() - lengthToRemove); memcpy(buffer.characters(), characters(), position * sizeof(UChar)); memcpy(buffer.characters() + position, characters() + position + lengthToRemove, (length() - lengthToRemove - position) * sizeof(UChar)); m_impl = StringImpl::adopt(buffer); }
PassRefPtr<StringImpl> StringImpl::replace(unsigned position, unsigned lengthToReplace, StringImpl* str) { position = min(position, length()); lengthToReplace = min(lengthToReplace, length() - position); unsigned lengthToInsert = str ? str->length() : 0; if (!lengthToReplace && !lengthToInsert) return this; StringBuffer buffer(length() - lengthToReplace + lengthToInsert); memcpy(buffer.characters(), characters(), position * sizeof(UChar)); if (str) memcpy(buffer.characters() + position, str->characters(), lengthToInsert * sizeof(UChar)); memcpy(buffer.characters() + position + lengthToInsert, characters() + position + lengthToReplace, (length() - position - lengthToReplace) * sizeof(UChar)); return adopt(buffer); }
void CXMLDocument::elementDataCallback(void *ctx,const xmlChar *ch,int len) { if (allowcallbacks) CB_elementData((const char *)ch,len); if (buildtree) characters(ctx,ch,len); }
void String::remove(unsigned position, int lengthToRemove) { if (lengthToRemove <= 0) return; if (position >= length()) return; if (static_cast<unsigned>(lengthToRemove) > length() - position) lengthToRemove = length() - position; UChar* data; RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(length() - lengthToRemove, data); memcpy(data, characters(), position * sizeof(UChar)); memcpy(data + position, characters() + position + lengthToRemove, (length() - lengthToRemove - position) * sizeof(UChar)); m_impl = newImpl.release(); }
/*! \internal This function may be called instead of characters() if, and only if, \a value consists only of whitespace. The caller gurantees that \a value is not empty. \e Whitespace refers to a sequence of characters that are either spaces, tabs, or newlines, in any order. In other words, not all the Unicode whitespace category is considered whitespace here. However, there is no guarantee or requirement that whitespaceOnly() is called for text nodes containing whitespace only. characters() may be called just as well. This is why the default implementation for whitespaceOnly() calls characters(). \sa characters() */ void QAbstractXmlReceiver::whitespaceOnly(const QStringRef &value) { Q_ASSERT_X(value.toString().trimmed().isEmpty(), Q_FUNC_INFO, "The caller must guarantee only whitespace is passed. Use characters() in other cases."); const QString &v = value.toString(); characters(QStringRef(&v)); }
/* 绘制屏幕上的内容。 * 注意程序在绘图之前调用了prepare_buffer,结束前调用了display_buffer。 * prepare_buffer会准备一个空白的绘图缓冲区,display_buffer则会将缓冲区绘制到屏幕上, * draw_pixel或draw_string绘制的内容将保存在缓冲区内(暂时不会显示在屏幕上),调用 * display_buffer后才会显示。 */ void redraw_screen() { fly_t it; const char *hit, *miss; prepare_buffer(); /* 准备缓冲区 */ /* 绘制每个字符 */ for (it = characters(); it != NULL; it = it->_next) { static char buf[2]; buf[0] = it->text + 'A'; buf[1] = 0; draw_string(buf, F2int(it->x), it->y, 15); } /* 绘制命中数、miss数、最后一次按键扫描码和fps */ draw_string(itoa(last_key_code()), SCR_HEIGHT - 8, 0, 48); hit = itoa(get_hit()); draw_string(hit, 0, SCR_WIDTH - strlen(hit) * 8, 10); miss = itoa(get_miss()); draw_string(miss, SCR_HEIGHT - 8, SCR_WIDTH - strlen(miss) * 8, 12); draw_string(itoa(get_fps()), 0, 0, 14); draw_string("FPS", 0, strlen(itoa(get_fps())) * 8, 14); display_buffer(); /* 绘制缓冲区 */ }
void String::truncate(unsigned position) { if (position >= length()) return; StringBuffer buffer(position); memcpy(buffer.characters(), characters(), position * sizeof(UChar)); m_impl = StringImpl::adopt(buffer); }
PassRefPtr<StringImpl> StringImpl::replace(unsigned position, unsigned lengthToReplace, StringImpl* str) { position = min(position, length()); lengthToReplace = min(lengthToReplace, length() - position); unsigned lengthToInsert = str ? str->length() : 0; if (!lengthToReplace && !lengthToInsert) return this; UChar* data; PassRefPtr<StringImpl> newImpl = createUninitialized(length() - lengthToReplace + lengthToInsert, data); memcpy(data, characters(), position * sizeof(UChar)); if (str) memcpy(data + position, str->characters(), lengthToInsert * sizeof(UChar)); memcpy(data + position + lengthToInsert, characters() + position + lengthToReplace, (length() - position - lengthToReplace) * sizeof(UChar)); return newImpl; }
bool QXmlDefaultHandler_QtDShell::__override_characters(const QString& ch0, bool static_call) { if (static_call) { return QXmlDefaultHandler::characters((const QString& )ch0); } else { return characters((const QString& )ch0); } }
int mesage_SaveFieldBinary(lua_State* L) { int err = 0; char *b = NULL; CMessage* msg = cmessage_arg(L, "mesage_AddFieldBinary"); CString fldName = luaL_checkstring(L, 2); CString path = luaL_checkstring(L, 3); char *description; DWORD l; CDatum *d = msg->GetDatum(fldName); if (d->GetVarType() != (VT_ARRAY | VT_UI1) ) { err = -1; description = "Not Binary Data"; goto err; } { l = d->GetDataSize(); b = new char[l]; SAFEARRAY* pArray = d->value().parray; ASSERT(pArray->cDims == 1); // check we have 1 dimension array ASSERT(l == pArray->rgsabound[0].cElements * pArray->cbElements); // get size of array memcpy(b, (BYTE*)pArray->pvData, l); int charsLen = ::MultiByteToWideChar(CP_UTF8, 0, path, lstrlen(path), NULL, 0); std::wstring characters(charsLen, '\0'); ::MultiByteToWideChar(CP_UTF8, 0, path, lstrlen(path), &characters[0], charsLen); int pf; err = _wsopen_s(&pf, characters.c_str(), _O_BINARY | _O_CREAT | _O_TRUNC | _O_WRONLY, _SH_DENYRW, _S_IWRITE); if (err) { description = "Open File Error"; goto err; } if (l != _write(pf, (b), l)) { err = -2; description = "Write File Error"; goto err; } err = _close(pf); if (err){ description = "Close File Error"; goto err; } } err: if (b) delete[]b; lua_pushinteger(L, err); if (err) lua_pushstring(L, description); else lua_pushinteger(L, l); return 2; }
void String::truncate(unsigned position) { if (position >= length()) return; UChar* data; RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(position, data); memcpy(data, characters(), position * sizeof(UChar)); m_impl = newImpl.release(); }
/*! \internal Treats \a outputItem as a node and calls the appropriate function, e.g., attribute() or comment(), depending on its QXmlNodeModelIndex::NodeKind. This is a helper function that subclasses can use to multiplex Nodes received via item(). */ void QAbstractXmlReceiver::sendAsNode(const QPatternist::Item &outputItem) { Q_ASSERT(outputItem); Q_ASSERT(outputItem.isNode()); const QXmlNodeModelIndex asNode = outputItem.asNode(); switch(asNode.kind()) { case QXmlNodeModelIndex::Attribute: { const QString &v = outputItem.stringValue(); attribute(asNode.name(), QStringRef(&v)); return; } case QXmlNodeModelIndex::Element: { startElement(asNode.name()); /* First the namespaces, then attributes, then the children. */ asNode.sendNamespaces(this); sendFromAxis<QXmlNodeModelIndex::AxisAttribute>(asNode); sendFromAxis<QXmlNodeModelIndex::AxisChild>(asNode); endElement(); return; } case QXmlNodeModelIndex::Text: { const QString &v = asNode.stringValue(); characters(QStringRef(&v)); return; } case QXmlNodeModelIndex::ProcessingInstruction: { processingInstruction(asNode.name(), outputItem.stringValue()); return; } case QXmlNodeModelIndex::Comment: { comment(outputItem.stringValue()); return; } case QXmlNodeModelIndex::Document: { startDocument(); sendFromAxis<QXmlNodeModelIndex::AxisChild>(asNode); endDocument(); return; } case QXmlNodeModelIndex::Namespace: Q_ASSERT_X(false, Q_FUNC_INFO, "Not implemented"); } Q_ASSERT_X(false, Q_FUNC_INFO, QString::fromLatin1("Unknown node type: %1").arg(asNode.kind()).toUtf8().constData()); }
int mesage_AddFieldBinary(lua_State* L) { CMessage* msg = cmessage_arg(L, "mesage_AddFieldBinary"); CString fldName = luaL_checkstring(L, 2); CString path = luaL_checkstring(L, 3); int err; char *description; int charsLen = ::MultiByteToWideChar(CP_UTF8, 0, path, lstrlen(path), NULL, 0); std::wstring characters(charsLen, '\0'); ::MultiByteToWideChar(CP_UTF8, 0, path, lstrlen(path), &characters[0], charsLen); int pf; char *b = NULL; err = _wsopen_s(&pf, characters.c_str(), _O_BINARY | _O_RDONLY, _SH_DENYWR, _S_IREAD); if (err) { description = "Open File error"; goto err; } DWORD l = _filelength(pf); b = new char[l]; if (l != _read(pf, b, l)) { err = -1; description = "Read File error"; goto err; } err = _close(pf); if (err) { description = "Close File error"; goto err; } { COleSafeArray arr; arr.Create(VT_UI1, 1, &l); for (DWORD i = 0; i < l; i++) { arr.PutElement((long*)&i, &b[i]); } msg->AddDatum(fldName, arr); } err: if (b) delete []b; lua_pushinteger(L, err); if (err) lua_pushstring(L, description); else lua_pushinteger(L, l); return 2; }
void String::insert(const UChar* charactersToInsert, unsigned lengthToInsert, unsigned position) { if (position >= length()) { append(charactersToInsert, lengthToInsert); return; } ASSERT(m_impl); if (!lengthToInsert) return; ASSERT(charactersToInsert); StringBuffer buffer(length() + lengthToInsert); memcpy(buffer.characters(), characters(), position * sizeof(UChar)); memcpy(buffer.characters() + position, charactersToInsert, lengthToInsert * sizeof(UChar)); memcpy(buffer.characters() + position + lengthToInsert, characters() + position, (length() - position) * sizeof(UChar)); m_impl = StringImpl::adopt(buffer); }
float RenderCombineText::width(unsigned from, unsigned length, const Font& font, float xPosition, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow* glyphOverflow) const { if (!characters()) return 0; if (m_isCombined) return font.size(); return RenderText::width(from, length, font, xPosition, fallbackFonts, glyphOverflow); }
unsigned String::numGraphemeClusters() const { TextBreakIterator* it = characterBreakIterator(characters(), length()); if (!it) return length(); unsigned num = 0; while (textBreakNext(it) != TextBreakDone) ++num; return num; }
unsigned String::numCharactersInGraphemeClusters(unsigned numGraphemeClusters) const { TextBreakIterator* it = characterBreakIterator(characters(), length()); if (!it) return min(length(), numGraphemeClusters); for (unsigned i = 0; i < numGraphemeClusters; ++i) { if (textBreakNext(it) == TextBreakDone) return length(); } return textBreakCurrent(it); }
void String::insert(const UChar* charactersToInsert, unsigned lengthToInsert, unsigned position) { if (position >= length()) { append(charactersToInsert, lengthToInsert); return; } ASSERT(m_impl); if (!lengthToInsert) return; ASSERT(charactersToInsert); UChar* data; RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(length() + lengthToInsert, data); memcpy(data, characters(), position * sizeof(UChar)); memcpy(data + position, charactersToInsert, lengthToInsert * sizeof(UChar)); memcpy(data + position + lengthToInsert, characters() + position, (length() - position) * sizeof(UChar)); m_impl = newImpl.release(); }
void FormatterToSourceTree::charactersRaw( const XMLCh* const chars, const unsigned int length) { assert(m_document != 0); processAccumulatedText(); doProcessingInstruction(s_piTarget, s_piData); characters(chars, length); }
int main(int argc,char * args[]){ if(argc<2){ printf("skladnia %s nazwapliku",args[0]); /*args[0] zawiera zawsze nazwe programu, mozna wiec go uzyc aby poinstruowac usera o wlasciwej skladni*/ }else{ printf("Plik %s zawiera %d bajtow, %d wierszy\nSuma kontrolna to :%d\n",characters(args[1]),lines(args[1]),hash(args[1]) ); printf("Zaczyna sie tak:\n"); fivefirstlines(args[1]); printf("\nKonczy sie tak:\n"); fivelastlines(args[1]); } return 0; }
static String queryHTTPHeader(HINTERNET requestHandle, DWORD infoLevel) { DWORD bufferSize = 0; HttpQueryInfoW(requestHandle, infoLevel, 0, &bufferSize, 0); Vector<UChar> characters(bufferSize / sizeof(UChar)); if (!HttpQueryInfoW(requestHandle, infoLevel, characters.data(), &bufferSize, 0)) return String(); characters.removeLast(); // Remove NullTermination. return String::adopt(characters); }
bool SelectElement::saveFormControlState(const SelectElementData& data, const Element* element, String& value) { const Vector<Element*>& items = data.listItems(element); int length = items.size(); // FIXME: Change this code to use the new StringImpl::createUninitialized code path. Vector<char, 1024> characters(length); for (int i = 0; i < length; ++i) { OptionElement* optionElement = toOptionElement(items[i]); bool selected = optionElement && optionElement->selected(); characters[i] = selected ? 'X' : '.'; } value = String(characters.data(), length); return true; }
Fixnum* String::tr_replace(STATE, struct tr_data* tr_data) { if(tr_data->last > (native_int)size() || shared_->true_p()) { ByteArray* ba = ByteArray::create(state, tr_data->last + 1); data(state, ba); shared(state, Qfalse); } std::memcpy(data_->bytes, tr_data->tr, tr_data->last); data_->bytes[tr_data->last] = 0; num_bytes(state, Fixnum::from(tr_data->last)); characters(state, num_bytes_); return Fixnum::from(tr_data->steps); }
void LoginManager::processPasswordState(const QString& aLine, Client &aClient) { auto account = getAccountOrDie(aClient); if(!account) return; //aLine is a password QByteArray passwordBytes; passwordBytes.append(aLine); QString hash = QString(QCryptographicHash::hash(passwordBytes,QCryptographicHash::Md5).toHex()); if(account->getPasswordHash() != hash) { aClient.printRawLine("Wrong password. Disconnecting..."); aClient.setState(EClientStateQuit); return; } //password is correct account->confirmCreation(); aClient.printRawLine("Password is correct. Welcome back, " + account->name() + "."); QVector<unsigned long> characterUids = account->characters(); auto characters = world::objects<Person>(characterUids); if(characters.count() == 1) { //login to the character immediately auto person = characters[0]; if(person) { person->setDisconnected(false); aClient.setState(EClientStateNormal); aClient.linkToPerson(world::World::instance()->objectFactory()->getPtr<Person>(person->uid())); auto clientPtr = world::World::instance()->getClientPtr(aClient.id()); if(!clientPtr) qDebug() << "Bad client ptr for person " << person->name() << " " << QString::number(person->uid()); else person->attachClient(clientPtr); auto room = person->getRoom(); if(room) room->printDescription(*person, aClient); return; } //otherwise show account menu state_ = ELoginStateAccountMenu; } }
void String::append(const UChar* charactersToAppend, unsigned lengthToAppend) { if (!m_impl) { if (!charactersToAppend) return; m_impl = StringImpl::create(charactersToAppend, lengthToAppend); return; } if (!lengthToAppend) return; ASSERT(charactersToAppend); StringBuffer buffer(length() + lengthToAppend); memcpy(buffer.characters(), characters(), length() * sizeof(UChar)); memcpy(buffer.characters() + length(), charactersToAppend, lengthToAppend * sizeof(UChar)); m_impl = StringImpl::adopt(buffer); }
void sax_parser<_Handler,_Config>::body() { while (has_char()) { if (cur_char() == '<') { element(); if (!m_root_elem_open) // Root element closed. Stop parsing. return; } else if (m_nest_level) // Call characters only when in xml hierarchy. characters(); else next(); } }
void String::append(const UChar* charactersToAppend, unsigned lengthToAppend) { if (!m_impl) { if (!charactersToAppend) return; m_impl = StringImpl::create(charactersToAppend, lengthToAppend); return; } if (!lengthToAppend) return; ASSERT(charactersToAppend); UChar* data; RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(length() + lengthToAppend, data); memcpy(data, characters(), length() * sizeof(UChar)); memcpy(data + length(), charactersToAppend, lengthToAppend * sizeof(UChar)); m_impl = newImpl.release(); }
void XMLWriter::dataElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& data, const XMLString& attr1, const XMLString& value1, const XMLString& attr2, const XMLString& value2, const XMLString& attr3, const XMLString& value3) { AttributesImpl attributes; if (!attr1.empty()) attributes.addAttribute(XMLString(), XMLString(), attr1, CDATA, value1); if (!attr2.empty()) attributes.addAttribute(XMLString(), XMLString(), attr2, CDATA, value2); if (!attr3.empty()) attributes.addAttribute(XMLString(), XMLString(), attr3, CDATA, value3); if (data.empty()) { emptyElement(namespaceURI, localName, qname, attributes); } else { startElement(namespaceURI, localName, qname, attributes); characters(data); endElement(namespaceURI, localName, qname); } }
String::operator QString() const { if (!m_impl) return QString(); if (QStringData* qStringData = m_impl->qStringData()) { // The WTF string was adopted from a QString at some point, so we // can just adopt the QStringData like a regular QString copy. qStringData->ref.ref(); QStringDataPtr qStringDataPointer = { qStringData }; return QString(qStringDataPointer); } if (is8Bit() && !m_impl->has16BitShadow()) { // Asking for characters() of an 8-bit string will make a 16-bit copy internally // in WTF::String. Since we're going to copy the data to QStringData anyways, we // can do the conversion ourselves and save one copy. return QString::fromLatin1(reinterpret_cast<const char*>(characters8()), length()); } return QString(reinterpret_cast<const QChar*>(characters()), length()); }
static Something systemSystem(Thread *thread) { char *command = stringToChar(stackGetVariable(0, thread).object->value); FILE *f = popen(command, "r"); free(command); if (!f) { return NOTHINGNESS; } size_t bufferUsedSize = 0; int bufferSize = 50; Object *buffer = newArray(bufferSize); while (fgets((char *)buffer->value + bufferUsedSize, bufferSize - (int)bufferUsedSize, f) != NULL) { bufferUsedSize = strlen(buffer->value); if (bufferSize - bufferUsedSize < 2) { bufferSize *= 2; buffer = resizeArray(buffer, bufferSize); } } bufferUsedSize = strlen(buffer->value); EmojicodeInteger len = u8_strlen_l(buffer->value, bufferUsedSize); Object *so = newObject(CL_STRING); stackSetVariable(0, somethingObject(so), thread); String *string = so->value; string->length = len; Object *chars = newArray(len * sizeof(EmojicodeChar)); string = stackGetVariable(0, thread).object->value; string->characters = chars; u8_toucs(characters(string), len, buffer->value, bufferUsedSize); return stackGetVariable(0, thread); }