inline int64_t skipPattern(
				in_type & istr, 
				uint64_t & patlencodelen, 
				uint64_t & flagcodelen, 
				uint64_t & datalen
			)
			{
				uint32_t const patlen = decodeUTF8(istr,patlencodelen);
							
				if ( patlen == getTerminator() )
				{
					return -1;
				}
				else
				{
					uint32_t const flags = decodeUTF8(istr,flagcodelen);
					uint32_t const skip = (flags&1)?((patlen+1)/2):(patlen+3)/4;
					
					for ( uint64_t i = 0; i < skip; ++i )
						istr.get();

					datalen += skip;

					return patlen;
				}
			}
			inline int64_t skipPattern(
				in_type & istr, 
				uint64_t & codelen)
			{
				// decode pattern length
				uint32_t const patlen = decodeUTF8(istr,codelen);
							
				if ( patlen == getTerminator() )
				{
					return -1;
				}
				else
				{
					// decode flags
					uint32_t const flags = decodeUTF8(istr,codelen);
					// compute length of encoded pattern
					uint32_t const skip = (flags&1)?((patlen+1)/2):(patlen+3)/4;
					
					// skip pattern data
					for ( uint64_t i = 0; i < skip; ++i )
						istr.get();

					codelen += skip;

					return patlen;
				}
			}
Beispiel #3
0
int Font::getTextChar(const char *text, int pos, int *nextPos) {
    int ch;
    unsigned int len;
    if (encoding == Encoding::UTF8) {
        ch = decodeUTF8(&text[pos], &len);
        if (ch == -1) len = 1;
    } else if (encoding == Encoding::UTF16) {
        ch = decodeUTF16(&text[pos], &len);
        if (ch == -1) len = 2;
    } else {
        len = 1;
        ch = (unsigned char)text[pos];
    }

    if (nextPos) *nextPos = pos + len;
    return ch;
}
			static bool decode(
				pattern_type & pattern, in_type & istr,
				::libmaus::parallel::SynchronousCounter<uint64_t> & nextid
			)
			{
				try
				{
					// decode pattern length
					uint32_t const patlen = decodeUTF8(istr);
					
					// check for terminator
					if ( patlen == getTerminator() )
					{
						return false;
					}
					else
					{
						// decode flags
						uint32_t const flags = decodeUTF8(istr);
						
						// resize pattern
						try
						{
							pattern.spattern.resize(patlen);
						}
						catch(std::exception const & ex)
						{
							std::cerr << "exception while resizing pattern to length " << patlen << " in CompactFastDecoderBase::decode(): " << ex.what() << std::endl;
							throw;
						}
						
						// pattern has indeterminate bases
						if ( flags & 1 )
						{
							uint64_t const full = (patlen >> 1);		
							uint64_t const brok = patlen&1;
							std::string::iterator ita = pattern.spattern.begin();
							
							for ( uint64_t i = 0; i < full; ++i )
							{
								int v = istr.get();
								if ( v < 0 )
								{
									::libmaus::exception::LibMausException se;
									se.getStream() << "EOF in getNextPatternUnlocked()";
									se.finish();
									throw se;
								}

								*(ita++) = v & 0xF; v >>= 4;
								*(ita++) = v & 0xF; v >>= 4;
							}
							
							if ( brok )
							{
								int v = istr.get();
								if ( v < 0 )
								{
									::libmaus::exception::LibMausException se;
									se.getStream() << "EOF in getNextPatternUnlocked()";
									se.finish();
									throw se;
								}

								*(ita++) = v & 0xF; v >>= 4;				
							}
						}
						// pattern has determinate bases only
						else
						{
							// full bytes
							uint64_t const full = (patlen >> 2);		
							// fractional rest
							uint64_t const brok = patlen&3;
							std::string::iterator ita = pattern.spattern.begin();
							
							// decode full bytes (four symbols each)
							for ( uint64_t i = 0; i < full; ++i )
							{
								int v = istr.get();
								if ( v < 0 )
								{
									::libmaus::exception::LibMausException se;
									se.getStream() << "EOF in getNextPatternUnlocked()";
									se.finish();
									throw se;
								}

								*(ita++) = v & 0x3; v >>= 2;
								*(ita++) = v & 0x3; v >>= 2;
								*(ita++) = v & 0x3; v >>= 2;
								*(ita++) = v & 0x3; v >>= 2;
							}
							
							// decode fractional
							if ( brok == 3 )
							{
								int v = istr.get();
								if ( v < 0 )
								{
									::libmaus::exception::LibMausException se;
									se.getStream() << "EOF in getNextPatternUnlocked()";
									se.finish();
									throw se;
								}

								*(ita++) = v & 0x3; v >>= 2;
								*(ita++) = v & 0x3; v >>= 2;
								*(ita++) = v & 0x3; v >>= 2;
							}
							else if ( brok == 2 )