/**
 * This function tests if a given line (split into tokens) has the right components
 * to be registering a new variable.
 */
bool isRegisteringVariable(MavenCompiler* c, StringList tokens) {
	// what does it take to register a variable?
	// 1. must have a datatype.
	// 2. must not have brackets ().
	// 3. is allowed to have a default value, but be careful where its placed.
	// this function needs to be improved to work like dissectFunction()
	
	// skip other keywords
	int token;
	for(token = 0; token < tokens.length(); ++token)
		if(tokens[token] != "public" && tokens[token] != "private"
		   && tokens[token] != "static" && tokens[token] != "constant"
		   && tokens[token] != "constant" && tokens[token] != "writeonly")
			break;
	
	// check data type
	string rawtype = stripRawType(tokens[token]);
	if(!isDataType(rawtype) && !objectExists(c, rawtype) && !enumExists(c, rawtype))
		return false;
	
	// the rest
	for(int i = 0; i < tokens.length(); ++i) {
		for(int j = 0; j < tokens[i].length(); ++j) {
			if(tokens[i][j] == '=') return true;
			if(tokens[i][j] == '(' || tokens[i][j] == ')')
				return false;
		}
	}
	
	return true;
}
Example #2
0
bool enumExists(MavenCompiler* c, string name) {
	StringList items = split('.', name);
	int namespaceID = -1, objectID = -1;
	
	if(items.length() == 1) {
		// recognise ambiguous objects
		vector<int> found;
		for(namespaceID = 0; namespaceID < c->namespaces->length(); ++namespaceID) {
			objectID = findEnumID(c, namespaceID, items[0]);
			if(objectID >= 0)
				found.push_back(namespaceID);
		}
		--namespaceID;
		
		if(found.size() > 1)
			pushError(c, "Ambiguous enumerator '%s'", items[0]);
		return (found.size() == 1);
	} else if(items.length() == 2) {
		namespaceID = findNamespaceID(c, items[0]);
		if(namespaceID < 0)
			return false;
		objectID = findEnumID(c, namespaceID, items[1]);
		return (objectID >= 0);
	}
	
	return false;
}
Example #3
0
QString TAEval::listToString(StringList list){ // Parse a list of QStrings to a single QString
    QString result = QString("");
    for(int i=0; i<list.length();i++)
    {
        if(i==0) result += "~`";
        result += list[i];
        if(i==list.length()-1) result += "`~";
        else result += "~~";
    }
    return result;
}
Example #4
0
StringList *SWModule_impl::getKeyChildren() throw(CORBA::SystemException) {
	sword::SWKey *key = delegate->getKey();
	StringList *retVal = new StringList;
	int count = 0;

	sword::VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key);
	if (vkey) {
		retVal->length(6);
		SWBuf num;
		num.appendFormatted("%d", vkey->Testament());
		(*retVal)[0] = CORBA::string_dup(num.c_str());
		num = "";
		num.appendFormatted("%d", vkey->Book());
		(*retVal)[1] = CORBA::string_dup(num.c_str());
		num = "";
		num.appendFormatted("%d", vkey->Chapter());
		(*retVal)[2] = CORBA::string_dup(num.c_str());
		num = "";
		num.appendFormatted("%d", vkey->Verse());
		(*retVal)[3] = CORBA::string_dup(num.c_str());
		num = "";
		num.appendFormatted("%d", vkey->getChapterMax());
		(*retVal)[4] = CORBA::string_dup(num.c_str());
		num = "";
		num.appendFormatted("%d", vkey->getVerseMax());
		(*retVal)[5] = CORBA::string_dup(num.c_str());
	}
	else {
		TreeKeyIdx *tkey = SWDYNAMIC_CAST(TreeKeyIdx, key);
		if (tkey) {
			if (tkey->firstChild()) {
				do {
					count++;
				}
				while (tkey->nextSibling());
				tkey->parent();
			}
			retVal->length(count);
			count = 0;
			if (tkey->firstChild()) {
				do {
					(*retVal)[count++] = CORBA::string_dup(tkey->getLocalName());
				}
				while (tkey->nextSibling());
				tkey->parent();
			}
		}
	}
	return retVal;
}
Example #5
0
string keywordCatch(MavenCompiler* c, string line, MavenVariable& catchVar) {
	// strip out the catch
	string newCatch = line.substr(line.find('(') + 1, line.length() - line.find('(') - 2);
	
	// this can only be 2 words
	StringList words = split(' ', newCatch);
	if(words.length() != 2) {
		pushError(c, "Expecting two words in catch");
		return MAVEN_INVALID;
	}
	
	// make sure the first word is the name of a class
	// bug #26: and its extended from maven.Exception
	int namespaceID, objectID;
	findClass(c, words[0], namespaceID, objectID);
	if(namespaceID < 0 || objectID < 0) {
		pushError(c, "Unknown exception class %s", words[0]);
		return MAVEN_INVALID;
	}
	
	// make catchVar
	catchVar.name = words[1];
	catchVar.type = c->namespaces->at(namespaceID).name + "." + c->namespaces->at(namespaceID).objects->at(objectID)->name;
	
	// build C++ version of catch
	newCatch = c->namespaces->at(namespaceID).name + "::" + c->namespaces->at(namespaceID).objects->at(objectID)->name + "* " + words[1];
	return "catch(" + newCatch + ")";
}
Example #6
0
StringList StringList::setTypes(string str) {
	list.clear();
	StringList split = splitCommas(str);
	for(int i = 0; i < split.length(); ++i)
		list.push_back(split[i]);
	return *this;
}
Example #7
0
StringList *SWMgr_impl::getGlobalOptions() throw(CORBA::SystemException) {
	sword::StringList options = delegate->getGlobalOptions();
	StringList *retVal = new StringList;
	int count = 0;
	for (sword::StringList::iterator it = options.begin(); it != options.end(); it++) {
		count++;
	}
	retVal->length(count);
	count = 0;
	for (sword::StringList::iterator it = options.begin(); it != options.end(); it++) {
		(*retVal)[count++] = CORBA::string_dup(it->c_str());
	}
	return retVal;
}
Example #8
0
StringList *SWMgr_impl::getAvailableLocales() throw(CORBA::SystemException) {
	sword::StringList localeNames = LocaleMgr::getSystemLocaleMgr()->getAvailableLocales();
	StringList *retVal = new StringList;
	int count = 0;
	for (sword::StringList::iterator it = localeNames.begin(); it != localeNames.end(); it++) {
		count++;
	}
	retVal->length(count);
	count = 0;
	for (sword::StringList::iterator it = localeNames.begin(); it != localeNames.end(); it++) {
		(*retVal)[count++] = CORBA::string_dup(it->c_str());
	}
	return retVal;
}
Example #9
0
StringList *SWModule_impl::parseKeyList(const char *keyText) throw(CORBA::SystemException) {
	sword::VerseKey *parser = dynamic_cast<VerseKey *>(delegate->getKey());
	StringList *retVal = new StringList;
	if (parser) {
		sword::ListKey result;
		result = parser->ParseVerseList(keyText, *parser, true);
		int count = 0;
		for (result = sword::TOP; !result.Error(); result++) {
			count++;
		}
		retVal->length(count);
		count = 0;
		for (result = sword::TOP; !result.Error(); result++) {
			(*retVal)[count++] = CORBA::string_dup((const char *)result);
		}
	}
	else	{
		retVal->length(1);
		(*retVal)[0] = CORBA::string_dup(keyText);
	}

	return retVal;
}
Example #10
0
bool TestClear() {
    BEGIN_TEST;

    StringList list;
    list.push_front("bar");

    EXPECT_NONNULL(list.first());
    list.clear();
    EXPECT_NULL(list.next());
    EXPECT_NULL(list.first());
    EXPECT_EQ(list.length(), 0);

    END_TEST;
}
Example #11
0
/*
 * Verifies that a single subclass can be attached to a cue text voice start tag.
 * From http://dev.w3.org/html5/webvtt/#webvtt-cue-span-start-tag (11/27/2012)
 *	Cue span start tags consist of the following:
 *		1. A "<" character representing the beginning of the start tag.
 *		2. The tag name.
 *		3. Zero or more the following sequence representing a subclasses of the start tag
 *			3.1. A full stop "." character.
 *			3.2. A sequence of non-whitespace characters.
 *		4. If the start tag requires an annotation then a space or tab character followed by a sequence of 
 *		   non-whitespace characters representing the annotation.
 *		5. A ">" character repsenting the end of the start tag.
 */
TEST_F(PayloadVoiceTag,DISABLED_VoiceTagSingleSubclass)
{
	loadVtt( "payload/v-tag/v-tag-single-subclass.vtt" );

	const InternalNode *head = getHeadOfCue( 0 );

	ASSERT_TRUE( head->childCount() == 3 );
	ASSERT_EQ( Node::Voice, head->child( 1 )->kind() );

	StringList cssClasses = head->child( 1 )->toInternalNode()->cssClasses();
	String expectedString = String( (const byte *)"class", 5 );

	ASSERT_TRUE( cssClasses.length() == 1 );
	ASSERT_EQ(  expectedString.text(), cssClasses.stringAtIndex( 0 ).text() );
}
Example #12
0
StringList *SWModule_impl::getEntryAttribute(const char *level1, const char *level2, const char *level3, CORBA::Boolean filtered) throw(CORBA::SystemException) {
	delegate->RenderText();	// force parse
	std::vector<SWBuf> results;
	StringList *retVal = new StringList;
	int count = 0;

	sword::AttributeTypeList &entryAttribs = delegate->getEntryAttributes();
	sword::AttributeTypeList::iterator i1Start, i1End;
	sword::AttributeList::iterator i2Start, i2End;
	sword::AttributeValue::iterator i3Start, i3End;

	if ((level1) && (*level1)) {
		i1Start = entryAttribs.find(level1);
		i1End = i1Start;
		if (i1End != entryAttribs.end())
			i1End++;
	}
	else {
		i1Start = entryAttribs.begin();
		i1End   = entryAttribs.end();
	}
	for (;i1Start != i1End; i1Start++) {
		if ((level2) && (*level2)) {
			i2Start = i1Start->second.find(level2);
			i2End = i2Start;
			if (i2End != i1Start->second.end())
				i2End++;
		}
		else {
			i2Start = i1Start->second.begin();
			i2End   = i1Start->second.end();
		}
		for (;i2Start != i2End; i2Start++) {
			if ((level3) && (*level3)) {
				i3Start = i2Start->second.find(level3);
				i3End = i3Start;
				if (i3End != i2Start->second.end())
					i3End++;
			}
			else {
				i3Start = i2Start->second.begin();
				i3End   = i2Start->second.end();
			}
			for (;i3Start != i3End; i3Start++) {
				results.push_back(i3Start->second);
			}
			if (i3Start != i3End)
				break;
		}
		if (i2Start != i2End)
			break;
	}

	retVal->length(results.size());
	for (int i = 0; i < results.size(); i++) {
		if (filtered) {
			(*retVal)[i] = CORBA::string_dup(delegate->RenderText(results[i].c_str()));
		}
		else {
			(*retVal)[count++] = CORBA::string_dup(results[i].c_str());
		}
	}

	return retVal;
}
Example #13
0
string basename(string path) {
	StringList parts = split('/', path);
	return parts[parts.length() - 1];
}
Example #14
0
string getLastEntity(string str) {
	StringList items = split('.', str);
	return items[items.length() - 1];
}