Example #1
0
 StringView::StringView(const StringView &str, uint32 begin, uint32 end)
     : _str(str.c_str()+begin)
     , _length(end-begin)
 {
     ARC_ASSERT(begin <= str.length(),"Invalid StringView begin.");
     ARC_ASSERT(end <= str.length(), "Invalid StringView end");
 }
Example #2
0
	bool write_string(Slice<char>& buffer, StringView v)
	{
		if (buffer.size() < v.length()) return false;
		
		memcpy(buffer.ptr(), v.c_str(), v.length());
		buffer.trim_front(v.length());
		return true;
	}
Example #3
0
		void unroll_write(Slice<char> buffer, const T& head, Tail&&... tail)
		{
			bool ok;
			ok = write_string(buffer, head);
			if (!ok)
			{
				// flush
				std::cout.write(m_buffer, BUFFER_SIZE - buffer.size());
				// reset buffer
				buffer = make_slice<char>(m_buffer, (uint64)BUFFER_SIZE);
				// try again
				ok = write_string(buffer, head);
				if (!ok)
				{
					StringView error = " <ERROR> ";
					std::cout.write(error.c_str(), error.length());
				}
			}
			unroll_write(buffer, std::forward<Tail>(tail)...);
		}
Example #4
0
 void push(lua_State *state, StringView value)
 {
     lua_pushlstring(state,value.c_str(),value.length());
 }