示例#1
0
package_local boolean compileLiteral(String name) {
    int num = 0, sign = -1, idx = 0, len = strlen(name);
    if (charAt(name, 0) == '-') {
        sign = idx = 1;
    }
    int decimal = -10000;
    while (idx < len) {
        int chr = charAt(name, idx++);
        if (chr == '.') {
            decimal = 1;
        } else {
            int digit = '0' - chr;
            if (digit > 0 || digit < -9) return false; // NaN
            num = (num * 10) + digit;
            decimal *= 10;
        }
    }
    if (decimal < 0) {
        compilePushWord(name, toInteger(sign * num));
    } else {
        double real = (sign * num) / (double) decimal;
        compilePushWord(name, toDouble(real));
    }
    return true;

}
void Buffer::onUpdateUi() {
    if (m_braceHighlight && selectionEmpty()) {
        sptr_t position = currentPos();
        sptr_t braceStart = -1;
        // Check previous character first.
        if (position != 0 && isBrace(charAt(position - 1))) {
            braceStart = position - 1;
        } else if (isBrace(charAt(position))) { // Check next character.
            braceStart = position;
        }
        if (braceStart != -1) {
            // Brace found
            sptr_t braceEnd = braceMatch(braceStart);
            if (braceEnd > 0) {
                braceHighlight(braceStart, braceEnd);
            } else {
                // Missing matching brace.
                braceBadLight(braceStart);
            }
        } else {
            // Not a brace, clear indicators.
            braceBadLight(-1);
        }
    }
}
示例#3
0
void TextShow::resizeEvent(QResizeEvent *e)
{
#ifdef WIN32
	if (inResize()){
		if (!m_timer->isActive()){
			setHScrollBarMode(AlwaysOff);
			setVScrollBarMode(AlwaysOff);
			m_timer->start(100);
		}
		return;
	}
#endif
    QPoint p = QPoint(0, height());
    p = mapToGlobal(p);
    p = viewport()->mapFromGlobal(p);
    int x, y;
    viewportToContents(p.x(), p.y(), x, y);
	int para;
    int pos = charAt(QPoint(x, y), &para);
    QTextEdit::resizeEvent(e);
    if (pos == -1){
        scrollToBottom();
    }else{
        setCursorPosition(para, pos);
        ensureCursorVisible();
    }
	sync();
	viewport()->repaint();
}
void
RAbstractStringRef::getBytes(unsigned char *buf, unsigned int bufsize,
                             unsigned int index) const
{
  if(!bufsize || !buf)
  {
    return;
  }

  if(index >= length())
  {
    buf[0] = 0;
    return;
  }

  unsigned int copySize = 0;

  copySize = length() - index - 1;

  if(bufsize < copySize)
  {
    copySize = bufsize;
  }

  // Very slow way to copy bytes, you have better override this copy method!
  unsigned char *bufEnd = buf + copySize;

  for(; buf < bufEnd; ++buf, ++index)
  {
    *buf = static_cast<unsigned char>(charAt(index));
  }

  *buf = 0;
}
unsigned char
RAbstractStringRef::equalsIgnoreCase(const RAbstractStringRef &s) const
{
  if(this == &s)
  {
    return true;
  }

  if(length() != s.length())
  {
    return false;
  }

  if(length() == 0)
  {
    return true;
  }

  for(unsigned int i = 0; i < length(); ++i)
  {
    if(tolower(charAt(i)) != tolower(s.charAt(i)))
    {
      return false;
    }
  }

  return true;
}
XalanDOMString&
GetXSLFileName(const XalanDOMString&        theXMLFileName, XalanDOMString& theResult)
{
    

    int         thePeriodIndex = -1;

    const int   theLength = length(theXMLFileName);

    for (int i = theLength - 1; i > 0; i--)
    {
        if (charAt(theXMLFileName, i) == XalanUnicode::charFullStop)
        {
            thePeriodIndex = i;

            break;
        }
    }

    if (thePeriodIndex != -1)
    {
         substring(theXMLFileName,
                              theResult,
                              0,
                              thePeriodIndex + 1);

        theResult.append("xsl");
    }

    return theResult;
}
SolvingInfo wallFollow(Labirinto l, Coordinate begin, void(*action)(int y, int x)){
	map=l.mapa;
	linhas=l.linhas;
	colunas=l.colunas;
	
	Coordinate position = begin;
	int direction=OESTE;	

	while(!haveMask(charAt(position.y,position.x), END)){
		Coordinate right = coordinateAtRight(position, direction);
		Coordinate front = coordinateAtFront(position, direction);
		if(haveMask(charAtCoordinate(right), WALL)){
			if(haveMask(charAtCoordinate(front), WALL)){
				direction = WIND_ROSE[(++windIndex)%4];
			} else {
				position = front;
				if(action!=NULL)action(position.y, position.x);
			}
		} else {
			direction = WIND_ROSE[(--windIndex+4)%4];
			position = right;
			if(action!=NULL)action(position.y, position.x);
		}
	}
}
示例#8
0
list<string> UTF8Utils::toCharArray() {
    list<string> ret;
    for (int i = 0; i < _length; i++) {
        ret.push_back(charAt(i));
    }
    return ret;
}
示例#9
0
package_local String getWord(FICL ficl) {
    /* start by dropping any leading space characters */
    do {
        if (ficl(sourcePointer) == ficl(sourceLength)) return null;
    } while (isSpace(charAt(ficl(source), ficl(sourcePointer)++)));
    int first = ficl(sourcePointer) - 1;
    // and go to where we have a space again
    do {
        if (ficl(sourcePointer) == ficl(sourceLength))
            return (substr(ficl(source), first));
    } while (!isSpace(charAt(ficl(source), ficl(sourcePointer)++)));
    
    String word = substr(ficl(source), first, ficl(sourcePointer) - 1);
    if (ficl(debuggingCompile)) print(strcat(word, ' '));
    return word;
}
示例#10
0
文件: ext_hh.cpp 项目: KOgames/hhvm
Variant HHVM_FUNCTION(serialize_memoize_param, const Variant& param) {
  // Memoize throws in the emitter if any function parameters are references, so
  // we can just assert that the param is cell here
  const auto& cell_param = *tvAssertCell(param.asTypedValue());
  auto type = param.getType();

  if (type == KindOfInt64) {
    return param;
  } else if (type == KindOfUninit || type == KindOfNull) {
    return s_empty;
  } else if (type == KindOfBoolean) {
    return param.asBooleanVal() ? s_true : s_false;
  } else if (type == KindOfString) {
    auto str = param.asCStrRef();
    if (str.empty()) {
      return s_emptyStr;
    } else if (str.charAt(0) > '9') {
      // If it doesn't start with a number, then we know it can never collide
      // with an int or any of our constants, so it's fine as is
      return param;
    }
  } else if (isContainer(cell_param) && getContainerSize(cell_param) == 0) {
    return s_emptyArr;
  }

  return fb_compact_serialize(param, FBCompactSerializeBehavior::MemoizeParam);
}
bool _NativeFrameworkDSString::isWhitespaceOnly(){
	if(isEmpty()) return true;
	for(int i=0; i<length(); i++)
		if(charAt(i) != 9)
			return false;
	return true;
}
示例#12
0
int StreamString::peek() {
    if(length()) {
        char c = charAt(0);
        return c;
    }
    return -1;
}
示例#13
0
string UTF8Utils::buildInnerString(int start, int len) {
    string ret = "";
    for (int i = start; i < start + len; i++) {
        ret += charAt(i);
    }
    return ret;
}
示例#14
0
string UTF8Utils::subStringStart(int start) {
    // substring
    string ret = "";
    for (int i = start; i < _length; i++) {
        ret += charAt(i);
    }
    return ret;
}
示例#15
0
文件: Bridge.cpp 项目: JdeH/LightOn
BOOL TCharSet::contains (char c) {
	{for (int charIndex = 0; charIndex < nrOfChars (); charIndex++) {
		if (charAt (charIndex) == c) {
			return TRUE;
		}
	}}
	return FALSE;
}
示例#16
0
string UTF8Utils::subStringEnd(int end) {
    // substring
    string ret = "";
    for (int i = 0; i < end; i++) {
        ret += charAt(i);
    }
    return ret;
}
示例#17
0
string UTF8Utils::subStringRange(int start, int end) {
    // substring
    string ret = "";
    for (int i = start; i < end; i++) {
        ret += charAt(i);
    }
    return ret;
}
示例#18
0
void QEditor::contentsMousePressEvent ( QMouseEvent * e ) {
    if (e->button() != Qt::RightButton) {
	e->ignore();
	return;
    }
    int line = 0;
    int col = charAt(e->pos(), &line);
    emit rightClicked(e->globalPos(), line, col);
}
示例#19
0
int StreamString::read() {
    if(length()) {
        char c = charAt(0);
        remove(0, 1);
        return c;

    }
    return -1;
}
XObjectPtr
FunctionLang::execute(
            XPathExecutionContext&  executionContext,
            XalanNode*              context,
            const XObjectPtr        arg1,
            const LocatorType*      /* locator */) const
{
    assert(arg1.null() == false);   

    const XalanNode*        parent = context;

    bool                    fMatch = false;

    const XalanDOMString&   lang = arg1->str();

    while(0 != parent)
    {
        if(XalanNode::ELEMENT_NODE == parent->getNodeType())
        {
            const XalanElement* const   theElementNode =
#if defined(XALAN_OLD_STYLE_CASTS)
                (const XalanElement*)parent;
#else
                static_cast<const XalanElement*>(parent);
#endif

            const XalanDOMString&       langVal =
                theElementNode->getAttributeNS(
                    DOMServices::s_XMLNamespaceURI,
                    s_attributeName);

            if(0 != length(langVal))
            {
                XPathExecutionContext::GetAndReleaseCachedString theGuard1(executionContext);
                XPathExecutionContext::GetAndReleaseCachedString theGuard2(executionContext);

                if(startsWith(toLowerCaseASCII(langVal, theGuard1.get()), toLowerCaseASCII(lang, theGuard2.get())))
                {
                    const XalanDOMString::size_type     valLen = length(lang);

                    if(length(langVal) == valLen ||
                       charAt(langVal, valLen) == XalanUnicode::charHyphenMinus)
                    {
                        fMatch = true;

                        break;
                    }
                }
            }
        }

        parent = DOMServices::getParentOfNode(*parent);
    }

    return executionContext.getXObjectFactory().createBoolean(fMatch);
}
示例#21
0
string UTF8Utils::replace(int index, const string &replace) {
    string ret = "";
    for (int i = 0; i < _length; i++) {
        string c = charAt(i);
        if (i != index) {
            ret += c;
        } else {
            ret += replace;
        }
    }
    return ret;
}
bool _NativeFrameworkDSString::startWith(string cppString){
	char indChar[cppString.length()];
	strcpy(indChar, cppString.c_str());
	bool match = true;
	int ctr = 0;
	while(cppString[ctr] != '\0' && match == true){
		if(cppString[ctr] != charAt(ctr++))
			match = false;
	}
	if(match)
		return true;
	return false;
}
示例#23
0
        static void sort(char* a[], int lo, int hi, int d, char* aux[]) {

        // cutoff to insertion sort for small subarrays
        if (hi <= lo + CUTOFF) {
            insertion(a, lo, hi, d);
            return;
        }

        // compute frequency counts
        int count[R+2];
        for(int i=0;i<R+2;i++){
                count[i]=0;
        }

        for (int i = lo; i <= hi; i++) {
            int c = charAt(a[i], d);
            count[c+2]++;
        }


        // transform counts to indicies
        for (int r = 0; r < R+1; r++)
            count[r+1] += count[r];

        // distribute
        for (int i = lo; i <= hi; i++) {
             int c = charAt(a[i], d);
            aux[count[c+1]++] = a[i];
        }

        // copy back
        for (int i = lo; i <= hi; i++)
            a[i] = aux[i - lo];


        // recursively sort for each character (excludes sentinel -1)
        for (int r = 0; r < R; r++)
            sort(a, lo + count[r], lo + count[r+1] - 1, d+1, aux);
    }
示例#24
0
void MsgViewBase::reload()
{
    QString t;
    vector<Msg_Id> msgs;
    unsigned i;
    for (i = 0; i < (unsigned)paragraphs(); i++){
        QString s = text(i);
        int n = s.find(MSG_ANCHOR);
        if (n < 0)
            continue;
        s = s.mid(n + strlen(MSG_ANCHOR));
        n = s.find("\"");
        if (n < 0)
            continue;
        string client;
        Msg_Id id;
        id.id = messageId(s.left(n), client);
        id.client = client;
        unsigned nn;
        for (nn = 0; nn < msgs.size(); nn++){
            if ((msgs[nn].id == id.id) && (msgs[nn].client == id.client))
                break;
        }
        if (nn >= msgs.size())
            msgs.push_back(id);
    }
    for (i = 0; i < msgs.size(); i++){
        Message *msg = History::load(msgs[i].id, msgs[i].client.c_str(), m_id);
        if (msg == NULL)
            continue;
        t += messageText(msg, false);
        delete msg;
    }
    QPoint p = QPoint(0, height());
    p = mapToGlobal(p);
    p = viewport()->mapFromGlobal(p);
    int x, y;
    viewportToContents(p.x(), p.y(), x, y);
    int para;
    int pos = charAt(QPoint(x, y), &para);
    setText(t);
    if (!CorePlugin::m_plugin->getOwnColors())
        setBackground(0);
    if (pos == -1){
        scrollToBottom();
    }else{
        setCursorPosition(para, pos);
        ensureCursorVisible();
    }
}
    static void sort(char* a[], int lo, int hi, int d) {

        // cutoff to insertion sort for small subarrays
        if (hi <= lo + CUTOFF) {
            insertion(a, lo, hi, d);
            return;
        }

        int lt = lo, gt = hi;
        int v = charAt(a[lo], d);
        int i = lo + 1;
        while (i <= gt) {
            int t = charAt(a[i], d);
            if      (t < v) exch(a, lt++, i++);
            else if (t > v) exch(a, i, gt--);
            else              i++;
        }

        // a[lo..lt-1] < v = a[lt..gt] < a[gt+1..hi].
        sort(a, lo, lt-1, d);
        if (v >= 0) sort(a, lt, gt, d+1);
        sort(a, gt+1, hi, d);
    }
示例#26
0
void QEditor::contentsMouseDoubleClickEvent( QMouseEvent * e )
{

    if ( e->button() != Qt::LeftButton ) {
        e->ignore();
        return;
    }

    int para = 0;
    int index = charAt( e->pos(), &para );

    emit doubleClicked(para, index);

}
示例#27
0
void TextShow::resizeEvent(QResizeEvent *e)
{
    QPoint p = QPoint(0, height());
    p = mapToGlobal(p);
    p = viewport()->mapFromGlobal(p);
    int x, y;
    viewportToContents(p.x(), p.y(), x, y);
    int para;
    int pos = charAt(QPoint(x, y), &para);
    QTextEdit::resizeEvent(e);
    if (pos == -1){
        scrollToBottom();
    }else{
        setCursorPosition(para, pos);
        ensureCursorVisible();
    }
}
int
RAbstractStringRef::indexOf(char ch, unsigned int fromIndex) const
{
  if(fromIndex >= length())
  {
    return -1;
  }

  for(unsigned int i = 0; i < length(); ++i)
  {
    if(charAt(i) == ch)
    {
      return static_cast<int>(i);
    }
  }

  return -1;
}
int
RAbstractStringRef::compareTo(const char *s) const
{
  unsigned int i = 0;

  for(; *s != '\0'; ++s, ++i)
  {
    if(i >= length())
    {
      return -1;
    }

    char iChar = charAt(i);
    char jChar = *s;

    if(iChar == jChar)
    {
      continue;
    }
    else if(iChar > jChar)
    {
      return 1;
    }
    else
    {
      return -1;
    }
  }

  if(length() == i)
  {
    return 0;
  }
  else if(length() > i)
  {
    return 1;
  }
  else
  {
    return -1;
  }
}
示例#30
0
int Term::separatingBit(const Term& other) const {
    int separating_bit = -1;
    int max_num = std::max(_num, other.getDecimal());
    for (size_t i = 0; max_num > 0; ++i) {
        if (charAt(i) != other.charAt(i)) {
            if (separating_bit != -1) {
                // we already had one bit separating between
                // the terms! that means the terms are separated
                // by two or more bits.
                return -1;
            }

            separating_bit = i;
        }

        max_num = max_num / 2;
    }

    return separating_bit;
}