Esempio n. 1
0
File: hash.cpp Progetto: Zoxc/mirb
	value_t Hash::to_s(Hash *self)
	{
		RecursionDetector<RecursionType::Hash_to_s, false> rd(self);

		if(rd.recursion())
			return String::get("{...}");

		CharArray result = "{";

		OnStack<1> os1(self);
		OnStackString<1> os2(result);

		HashAccess::each_pair(self, [&](value_t key, value_t value) -> bool {

			OnStack<1> os(value);
			
			result += inspect(key);
			result += "=>";
			result += inspect(value);
			result += ", ";

			return true;
		});

		if(result.size() > 1)
			result.shrink(result.size() - 2);

		result += "}";

		return result.to_string();
	}
Esempio n. 2
0
File: posix.cpp Progetto: Zoxc/mirb
		CharArray NativeStream::read(size_t length)
		{
			CharArray buf;
			buf.buffer(length);

			ssize_t result = ::read(fd, buf.str_ref(), buf.size());

			if(result < 0)
				raise("Unable to read from file descriptor");

			buf.shrink((size_t)result);
			return buf;
		}