Exemplo n.º 1
0
static void setMemRefType(ArmLIR *lir, bool isLoad, int memType)
{
    u8 *maskPtr;
    u8 mask = ENCODE_MEM;;
    assert(getEncoding(lir->opcode)->flags & (IS_LOAD | IS_STORE));
    if (isLoad) {
        maskPtr = &lir->useMask;
    } else {
        maskPtr = &lir->defMask;
    }
    /* Clear out the memref flags */
    *maskPtr &= ~mask;
    /* ..and then add back the one we need */
    switch(memType) {
        case kLiteral:
            assert(isLoad);
            *maskPtr |= ENCODE_LITERAL;
            break;
        case kDalvikReg:
            *maskPtr |= ENCODE_DALVIK_REG;
            break;
        case kHeapRef:
            *maskPtr |= ENCODE_HEAP_REF;
            break;
        case kMustNotAlias:
            /* Currently only loads can be marked as kMustNotAlias */
            assert(!(getEncoding(lir->opcode)->flags & IS_STORE));
            *maskPtr |= ENCODE_MUST_NOT_ALIAS;
            break;
        default:
            ALOGE("Jit: invalid memref kind - %d", memType);
            assert(0);  // Bail if debug build, set worst-case in the field
            *maskPtr |= ENCODE_ALL;
    }
}
Exemplo n.º 2
0
string HuffmanTree::getEncoding(unsigned char input, BSTNode* nodePtr)
{
  if(nodePtr)
	{
	  if(nodePtr->data.letter == input)
		{
		  // cout << nodePtr->data.letter << endl;
		//if((nodePtr->left == nullptr) && (nodePtr->right == nullptr))
		  return (nodePtr->data.encoding);
		}

	  string output = "";
	  
	  if(nodePtr->left)
		output = getEncoding(input, nodePtr->left);
	  if(output != "")
		return output;

	  if(nodePtr->right)
		output = getEncoding(input, nodePtr->right);
	  if(output != "")
		return output;
	}

  else
	{
	  cout << "Error accessing Huffman Tree." << endl;
	}
  
  return "";
}
Exemplo n.º 3
0
const Ref<TextEncoding>& TextEncoding::detectEncodingSimple(const char* str, int length, bool strict)
{
    if (LN_REQUIRE(str))
        return Ref<TextEncoding>::Null;

    // check UTF8 BOM
    if (length >= 3) {
        const byte_t bom[] = {0xEF, 0xBB, 0xBF};
        if (memcmp(static_cast<const void*>(str), static_cast<const void*>(bom), 3) == 0) {
            return getEncoding(EncodingType::UTF8);
        }
    }

    int utf8pt = 0;
    int localPt = 0;
    const uint8_t* s = (const uint8_t*)str;
    const uint8_t* end = (const uint8_t*)str + length;
    int extra = 0;
    while (s < end) {
        if (*s == 0x00) {
            // 有効範囲内に 0 があった。バイナリかもしれない
            if (strict)
                return Ref<TextEncoding>::Null;
            else
                return getEncoding(EncodingType::ASCII);
        } else if (*s <= 0x7F) {
            // ASCII
            s++;
        } else {
            if (UnicodeUtils::checkUTF8TrailingBytes((const UTF8*)s, (const UTF8*)end, true, &extra) == UTFConversionResult_Success) {
                // UTF8
                utf8pt += 1;
                //s += extra;
            }

            {
                // それ以外 (SJIS など)
                localPt++;
            }
            s++;
        }
    }

    if (utf8pt == 0 && localPt == 0) {
        return getEncoding(EncodingType::ASCII);
    } else if (utf8pt >= localPt) {
        return getEncoding(EncodingType::UTF8N);
    } else {
        return systemMultiByteEncoding();
    }
}
Exemplo n.º 4
0
void YahooInfo::apply()
{
    YahooUserData *data = m_data;
    if (data == NULL)
        data = &m_client->data.owner;
    getEncoding(data, m_data == NULL);
}
Exemplo n.º 5
0
/*
 * Set up the accurate resource mask for branch instructions
 */
static void relaxBranchMasks(ArmLIR *lir)
{
    int flags = getEncoding(lir->opcode)->flags;

    /* Make sure only branch instructions are passed here */
    assert(flags & IS_BRANCH);

    lir->useMask = lir->defMask = ENCODE_REG_PC;

    if (flags & REG_DEF_LR) {
        lir->defMask |= ENCODE_REG_LR;
    }

    if (flags & (REG_USE0 | REG_USE1 | REG_USE2 | REG_USE3)) {
        int i;

        for (i = 0; i < 4; i++) {
            if (flags & (1 << (kRegUse0 + i))) {
                setupRegMask(&lir->useMask, lir->operands[i]);
            }
        }
    }

    if (flags & USES_CCODES) {
        lir->useMask |= ENCODE_CCODE;
    }
}
Exemplo n.º 6
0
AudioFile::SampleType AudioFileReaderInternal::getSampleType() const throw()
{    
    const AudioFile::Encoding encoding = getEncoding();
    const int bytesPerSample = getBytesPerSample();
    const bool isPCM = encoding & AudioFile::EncodingFlagPCM;
    const bool isFloat = encoding & AudioFile::EncodingFlagFloat;

    if (isPCM)
    {        
        switch (bytesPerSample)
        {
            case 2: return AudioFile::Short;
            case 3: return AudioFile::Int24;
            case 4: return AudioFile::Int;
            case 1: return AudioFile::Char;
            default: goto exit;
        }        
    }
    else if (isFloat)
    {
        switch (bytesPerSample)
        {
            case 4: return AudioFile::Float;
            case 8: return AudioFile::Double;
            default: goto exit;
        }                
    }
    
exit:
    return AudioFile::Invalid;
}
Exemplo n.º 7
0
const std::vector<int> getConversionCode(std::string src_encoding, std::string dst_encoding)
{
  Encoding src_encod = getEncoding(src_encoding);
  Encoding dst_encod = getEncoding(dst_encoding);
  bool is_src_color_format = enc::isColor(src_encoding) || enc::isMono(src_encoding) ||
                             enc::isBayer(src_encoding) || (src_encoding == enc::YUV422);
  bool is_dst_color_format = enc::isColor(dst_encoding) || enc::isMono(dst_encoding) ||
                             enc::isBayer(dst_encoding) || (dst_encoding == enc::YUV422);
  bool is_num_channels_the_same = (enc::numChannels(src_encoding) == enc::numChannels(dst_encoding));

  // If we have no color info in the source, we can only convert to the same format which
  // was resolved in the previous condition. Otherwise, fail
  if (!is_src_color_format) {
    if (is_dst_color_format)
      throw Exception("[" + src_encoding + "] is not a color format. but [" + dst_encoding +
                      "] is. The conversion does not make sense");
    if (!is_num_channels_the_same)
      throw Exception("[" + src_encoding + "] and [" + dst_encoding + "] do not have the same number of channel");
    return std::vector<int>(1, SAME_FORMAT);
  }

  // If we are converting from a color type to a non color type, we can only do so if we stick
  // to the number of channels
  if (!is_dst_color_format) {
    if (!is_num_channels_the_same)
      throw Exception("[" + src_encoding + "] is a color format but [" + dst_encoding + "] " +
                      "is not so they must have the same OpenCV type, CV_8UC3, CV16UC1 ....");
    return std::vector<int>(1, SAME_FORMAT);
  }

  // If we are converting from a color type to another type, then everything is fine
  static const std::map<std::pair<Encoding, Encoding>, std::vector<int> > CONVERSION_CODES = getConversionCodes();

  std::pair<Encoding, Encoding> key(src_encod, dst_encod);
  std::map<std::pair<Encoding, Encoding>, std::vector<int> >::const_iterator val = CONVERSION_CODES.find(key);
  if (val == CONVERSION_CODES.end())
    throw Exception("Unsupported conversion from [" + src_encoding +
                      "] to [" + dst_encoding + "]");

  // And deal with depth differences if the colors are different
  std::vector<int> res = val->second;
  if ((enc::bitDepth(src_encoding) != enc::bitDepth(dst_encoding)) && (getEncoding(src_encoding) != getEncoding(dst_encoding)))
    res.push_back(SAME_FORMAT);

  return res;
}
Exemplo n.º 8
0
static ArmLIR *newLIR3(CompilationUnit *cUnit, ArmOpcode opcode,
                           int dest, int src1, int src2)
{
    ArmLIR *insn = (ArmLIR *) dvmCompilerNew(sizeof(ArmLIR), true);
    if (!(getEncoding(opcode)->flags & IS_TERTIARY_OP)) {
        ALOGE("Bad LIR3: %s[%d]",EncodingMap[opcode].name,opcode);
    }
    assert(isPseudoOpcode(opcode) ||
           (getEncoding(opcode)->flags & IS_TERTIARY_OP));
    insn->opcode = opcode;
    insn->operands[0] = dest;
    insn->operands[1] = src1;
    insn->operands[2] = src2;
    setupResourceMasks(insn);
    dvmCompilerAppendLIR(cUnit, (LIR *) insn);
    return insn;
}
	//-------------------------------------------------------------------------------------------------
	void EncodingSettings::setupStreamEncoding(const DataStreamExPtr& _dataStream, const String& _defaultEncoding)
	{
		String encoding = _dataStream->getEncoding();
		if(encoding.empty())
		{
			String encoding = getEncoding(_dataStream->getName(), _defaultEncoding);
			_dataStream->setEncoding(encoding);
		}
	}
Exemplo n.º 10
0
qpid::types::Variant Message::getAnnotation(const std::string& key) const
{
    qpid::types::Variant::Map::const_iterator i = annotations.find(key);
    if (i != annotations.end()) return i->second;
    //FIXME: modify Encoding interface to allow retrieval of
    //annotations of different types from the message data as received
    //off the wire
    return qpid::types::Variant(getEncoding().getAnnotationAsString(key));
}
Exemplo n.º 11
0
/*
 * The following are building blocks to construct low-level IRs with 0 - 4
 * operands.
 */
static ArmLIR *newLIR0(CompilationUnit *cUnit, ArmOpcode opcode)
{
    ArmLIR *insn = (ArmLIR *) dvmCompilerNew(sizeof(ArmLIR), true);
    assert(isPseudoOpcode(opcode) || (getEncoding(opcode)->flags & NO_OPERAND));
    insn->opcode = opcode;
    setupResourceMasks(insn);
    dvmCompilerAppendLIR(cUnit, (LIR *) insn);
    return insn;
}
Exemplo n.º 12
0
void UserConnection::send(const string &aString) {
    lastActivity = GET_TICK();
    COMMAND_DEBUG((Util::stricmp(getEncoding(), Text::utf8) != 0 ? Text::toUtf8(aString, getEncoding()) : aString), DebugManager::CLIENT_OUT, getRemoteIp());
#ifdef LUA_SCRIPT
    if(onUserConnectionMessageOut(this, aString)) {
        disconnect(true);
        return;
    }
#endif
    socket->write(aString);
}
void MainWindow::load(QString path)
{
    QString chardet = charsetDetect(path);

    QString encoding = getEncoding(chardet);

    delete engine;
    engine = new SrtEngine(path, encoding);

    setup();
}
Exemplo n.º 14
0
void Message::addTraceId(const std::string& id)
{
    std::string trace = getEncoding().getAnnotationAsString(X_QPID_TRACE);
    if (trace.empty()) {
        addAnnotation(X_QPID_TRACE, id);
    } else if (trace.find(id) == std::string::npos) {
        trace += ",";
        trace += id;
        addAnnotation(X_QPID_TRACE, trace);
    }
}
Exemplo n.º 15
0
static ArmLIR *newLIR1(CompilationUnit *cUnit, ArmOpcode opcode,
                           int dest)
{
    ArmLIR *insn = (ArmLIR *) dvmCompilerNew(sizeof(ArmLIR), true);
    assert(isPseudoOpcode(opcode) || (getEncoding(opcode)->flags & IS_UNARY_OP));
    insn->opcode = opcode;
    insn->operands[0] = dest;
    setupResourceMasks(insn);
    dvmCompilerAppendLIR(cUnit, (LIR *) insn);
    return insn;
}
Exemplo n.º 16
0
void Message::addTraceId(const std::string& id)
{
    std::string trace = getEncoding().getAnnotationAsString(X_QPID_TRACE);
    if (trace.empty()) {
        annotations[X_QPID_TRACE] = id;
    } else if (trace.find(id) == std::string::npos) {
        trace += ",";
        trace += id;
        annotations[X_QPID_TRACE] = trace;
    }
    annotationsChanged();
}
Exemplo n.º 17
0
utility::stream::size_type body::getGeneratedSize(const generationContext& ctx)
{
	// MIME-Multipart
	if (getPartCount() != 0)
	{
		utility::stream::size_type size = 0;

		// Size of parts and boundaries
		for (size_t p = 0 ; p < getPartCount() ; ++p)
		{
			size += 100;  // boundary, CRLF...
			size += getPartAt(p)->getGeneratedSize(ctx);
		}

		// Size of prolog/epilog text
		const text prologText = getActualPrologText(ctx);

		if (!prologText.isEmpty())
		{
			std::ostringstream oss;
			utility::outputStreamAdapter osa(oss);

			prologText.encodeAndFold(ctx, osa, 0,
				NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE);

			size += oss.str().size();
		}

		const text epilogText = getActualEpilogText(ctx);

		if (!epilogText.isEmpty())
		{
			std::ostringstream oss;
			utility::outputStreamAdapter osa(oss);

			epilogText.encodeAndFold(ctx, osa, 0,
				NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE);

			size += oss.str().size();
		}

		return size;
	}
	// Simple body
	else
	{
		ref <utility::encoder::encoder> srcEncoder = m_contents->getEncoding().getEncoder();
		ref <utility::encoder::encoder> dstEncoder = getEncoding().getEncoder();

		return dstEncoder->getEncodedSize(srcEncoder->getDecodedSize(m_contents->getLength()));
	}
}
Exemplo n.º 18
0
static int recoverOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
  Recover *pRecover = (Recover*)pVTab;
  u32 iRootPage;                   
  int iEncoding;                   
  unsigned nPageSize;              
  Pager *pPager;                   
  RecoverLeafCursor *pLeafCursor;  
  RecoverCursor *pCursor;          
  int rc;

  FNENTRY();

  iRootPage = 0;
  rc = getRootPage(pRecover->db, pRecover->zDb, pRecover->zTable,
                   &iRootPage);
  if( rc!=SQLITE_OK ){
    return rc;
  }

  iEncoding = 0;
  rc = getEncoding(pRecover->db, pRecover->zDb, &iEncoding);
  if( rc!=SQLITE_OK ){
    return rc;
  }

  rc = GetPager(pRecover->db, pRecover->zDb, &pPager, &nPageSize);
  if( rc!=SQLITE_OK ){
    return rc;
  }

  rc = leafCursorCreate(pPager, nPageSize, iRootPage, &pLeafCursor);
  if( rc!=SQLITE_OK ){
    return rc;
  }

  pCursor = sqlite3_malloc(sizeof(RecoverCursor));
  if( !pCursor ){
    leafCursorDestroy(pLeafCursor);
    return SQLITE_NOMEM;
  }
  memset(pCursor, 0, sizeof(*pCursor));
  pCursor->base.pVtab = pVTab;
  pCursor->pLeafCursor = pLeafCursor;
  pCursor->iEncoding = iEncoding;

  
  pCursor->bEOF = (pLeafCursor->pPage==NULL);

  *ppCursor = (sqlite3_vtab_cursor*)pCursor;
  return SQLITE_OK;
}
Exemplo n.º 19
0
void Message::computeExpiration(const boost::intrusive_ptr<ExpiryPolicy>& e)
{
    //TODO: this is still quite 0-10 specific...
    uint64_t ttl;
    if (getEncoding().getTtl(ttl)) {
        if (e) {
            // Use higher resolution time for the internal expiry calculation.
            // Prevent overflow as a signed int64_t
            Duration duration(std::min(ttl * TIME_MSEC,
                                       (uint64_t) std::numeric_limits<int64_t>::max()));
            expiration = AbsTime(e->getCurrentTime(), duration);
            setExpiryPolicy(e);
        }
    }
}
Exemplo n.º 20
0
static ArmLIR *newLIR4(CompilationUnit *cUnit, ArmOpcode opcode,
                       int dest, int src1, int src2, int info)
{
    ArmLIR *insn = (ArmLIR *) dvmCompilerNew(sizeof(ArmLIR), true);
    assert(isPseudoOpcode(opcode) ||
           (getEncoding(opcode)->flags & IS_QUAD_OP));
    insn->opcode = opcode;
    insn->operands[0] = dest;
    insn->operands[1] = src1;
    insn->operands[2] = src2;
    insn->operands[3] = info;
    setupResourceMasks(insn);
    dvmCompilerAppendLIR(cUnit, (LIR *) insn);
    return insn;
}
Exemplo n.º 21
0
bool Message::isExcluded(const std::vector<std::string>& excludes) const
{
    std::string traceStr = getEncoding().getAnnotationAsString(X_QPID_TRACE);
    if (traceStr.size()) {
        std::vector<std::string> trace = split(traceStr, ", ");
        for (std::vector<std::string>::const_iterator i = excludes.begin(); i != excludes.end(); i++) {
            for (std::vector<std::string>::const_iterator j = trace.begin(); j != trace.end(); j++) {
                if (*i == *j) {
                    return true;
                }
            }
        }
    }
    return false;
}
Exemplo n.º 22
0
unsigned int Encoding::decode(int *dest, unsigned int dest_size, const unsigned char *src, unsigned int src_size, EncodingType encoding)
{
	// auto encoding judgement
	if (encoding == NONE) encoding = getEncoding(src, src_size);

	// dispatching
	switch (encoding) {
	case UTF16: return ::decode_utf16(dest, dest_size, src, src_size);
	case UTF8: return ::decode_utf8(dest, dest_size, src, src_size);
	case SHIFTJIS: return ::decode_shiftjis(dest, dest_size, src, src_size);
	case EUCJP: return ::decode_eucjp(dest, dest_size, src, src_size);
	}

	// unknown encoding.
	return 0;
}
Exemplo n.º 23
0
void MainWindow::dropEvent(QDropEvent *e)
{
    this->hide();
    //qDebug() << "dropEvent";
    QString path = e->mimeData()->urls()[0].toLocalFile();
    //qDebug() << "Dropped file:" << path;
    if (!path.isNull() && path.right(4) == ".srt") {
        QString encoding = getEncoding();

        delete engine;
        engine = new SrtEngine(path, encoding);
        //

        //qDebug() << "Correct File Type";
        setup();
    }
    this->show();
}
Exemplo n.º 24
0
int  FileEncoding::investigate(const std::string& c, const std::string& h )
{
	// get encoding
	getEncoding(c,h);

	// check eol mode 
	size_t p = c.find_first_of("\r\n");
	if ( p != std::string::npos )
	{
		if ( c[p] == 0x0a )
			eol_ = UNIX;
		else
			eol_ = DOS;
	}

	// check for binaries
	isBinary_ = false;
	p = 0;
	while ( (c[p]) && (p < c.size()) )
		p++;

	if ( p < c.size() )
	{
		switch ( codePage_ )
		{
			case CP_WINUNICODE :
			{
				//TODO: smell
				if ( (p != c.size()) && ((p+1)%2 != 0) )
					isBinary_ = true;
				break;
			}
			case CP_UTF8    :
			default		 :
			{
				if ( p != c.size() )
					isBinary_ = true;
				break;
			}
		}
	}
    return codePage_;
}
Exemplo n.º 25
0
void MainWindow::openFileDialog()
{
    this->hide();

    QString dir = settings.value("gen/dir").toString();
    if (!QDir(dir).exists()) dir = "";
    QString path = QFileDialog::getOpenFileName(0,
             tr("Open SRT File"), dir, tr("SRT Files (*.srt)"));

    if (!path.isNull()) {
        QString encoding = getEncoding();

        delete engine;
        engine = new SrtEngine(path, encoding);

        setup();
    }

    this->show();
}
StringBuffer MailSyncSourceConfig::print() {

    StringBuffer ret;
    ret = "** SOURCE: "; ret += getName(); ret += "**\r\n";
    
    ret += "URI:\t\t"; ret += getURI(); ret += "\r\n";
    ret += "SyncModes:\t"; ret += getSyncModes(); ret += "\r\n";
    ret += "Type:\t\t"; ret += getType(); ret += "\r\n";
    ret += "Sync:\t\t"; ret += getSync(); ret += "\r\n";
    ret += "Encoding:\t"; ret += getEncoding(); ret += "\r\n";
    ret += "Version:\t"; ret += getVersion(); ret += "\r\n";
    ret += "SupportedType:\t"; ret += getSupportedTypes(); ret += "\r\n";
    ret += "Last:\t\t"; ret.append(getLast()); ret += "\r\n";
    ret += "Encryption:\t"; ret += getEncryption(); ret += "\r\n";    
    ret += "Enabled:\t"; ret += (isEnabled() == true ? "1" : "0"); ret += "\r\n";    


    ret += "DownloadAge:\t"; ret.append(getDownloadAge()); ret += "\r\n";    
    ret += "BodySize:\t"; ret.append(getBodySize()); ret += "\r\n";
    ret += "AttachSize:\t"; ret.append(getAttachSize()); ret += "\r\n";

    return ret;
}
Exemplo n.º 27
0
void docSetup(DOMDocument *doc) {

	// Print out the doc

	DOMPrintFormatTarget* formatTarget = new DOMPrintFormatTarget();
	
    const XMLCh* encNameStr = XMLString::transcode("UTF-8");
    DOMNode *aNode = doc->getFirstChild();
    if (aNode->getNodeType() == DOMNode::ENTITY_NODE)
    {
        const XMLCh* aStr = ((DOMEntity *)aNode)->
#if defined XSEC_XERCES_DOMENTITYINPUTENCODING
            getInputEncoding();
#else
            getEncoding();
#endif

        if (!strEquals(aStr, ""))
        {
            encNameStr = aStr;
        }
    }
    xsecsize_t lent = XMLString::stringLen(encNameStr);
    gEncodingName = new XMLCh[lent + 1];
    XMLString::copyNString(gEncodingName, encNameStr, lent);
    gEncodingName[lent] = 0;

	
	
#if defined(XSEC_XERCES_FORMATTER_REQUIRES_VERSION)
	gFormatter = new XMLFormatter("UTF-8", 0, formatTarget,
                                          XMLFormatter::NoEscapes, gUnRepFlags);
#else
	gFormatter = new XMLFormatter("UTF-8", formatTarget,
                                          XMLFormatter::NoEscapes, gUnRepFlags);
#endif
}
Exemplo n.º 28
0
uint64_t Message::getMessageSize() const
{
    return getEncoding().getMessageSize();
}
Exemplo n.º 29
0
bool Message::isPersistent() const
{
    return getEncoding().isPersistent();
}
Exemplo n.º 30
0
std::string Message::getRoutingKey() const
{
    return getEncoding().getRoutingKey();
}