コード例 #1
0
/*!
 * Assuming a string of standard abiword properties eg. "fred:nerk; table-width:1.0in; table-height:10.in"
 * Return the value of the property sProp or NULL if it is not present.
 * This UT_String * should be deleted by the calling programming after it is finished with it.
 */
UT_String UT_String_getPropVal(const UT_String & sPropertyString, const UT_String & sProp)
{
	UT_String sWork(sProp);
	sWork += ":";

	const char * szWork = sWork.c_str();
	const char * szProps = sPropertyString.c_str();
	const char * szLoc = strstr(szProps,szWork);
	if(szLoc == NULL)
	{
		return UT_String();
	}
//
// Look if this is the last property in the string.
//
	const char * szDelim = strchr(szLoc,';');
	if(szDelim == NULL)
	{
//
// Remove trailing spaces
//
		UT_sint32 iSLen = strlen(szProps);
		while(iSLen > 0 && szProps[iSLen-1] == ' ')
		{
			iSLen--;
		}
//
// Calculate the location of the substring
//
		UT_sint32 offset = static_cast<UT_sint32>(reinterpret_cast<size_t>(szLoc) - reinterpret_cast<size_t>(szProps));
		offset += strlen(szWork);
		return UT_String(sPropertyString.substr(offset,(iSLen - offset)));
	}
	else
	{
		szDelim = strchr(szLoc,';');
		if(szDelim == NULL)
		{
//
// bad property string
//
			UT_ASSERT(UT_SHOULD_NOT_HAPPEN);
			return UT_String();
		}
//
// Remove trailing spaces.
//
		while(*szDelim == ';' || *szDelim == ' ')
		{
			szDelim--;
		}
//
// Calculate the location of the substring
//
		UT_sint32 offset = static_cast<UT_sint32>(reinterpret_cast<size_t>(szLoc) - reinterpret_cast<size_t>(szProps));
		offset += strlen(szWork);
		UT_sint32 iLen = static_cast<UT_sint32>(reinterpret_cast<size_t>(szDelim) - reinterpret_cast<size_t>(szProps)) + 1;
		return UT_String(sPropertyString.substr(offset,(iLen - offset)));
	}
}
コード例 #2
0
UT_String UT_String::substr(size_t iStart, size_t nChars) const
{
	const size_t nSize = pimpl->size();

	if (iStart >= nSize || !nChars) {
		return UT_String();
	}

	const char* p = pimpl->data() + iStart;
	if (iStart + nChars > nSize) {
		nChars = nSize - iStart;
	}

	return UT_String(p, nChars);
}
コード例 #3
0
void BIN_ProjectLoader::loadSpriteSheetNames( const STD_String &projectFolder, StringPairCol_t &sheetNames )
{
  // Todo, remove need for PL_FileSpec here!
  PL_FileSpec fileSpec( (projectFolder + "/spriteSheets").c_str() );

  for ( PL_FileSpec::iterator i = fileSpec.begin(), iEnd = fileSpec.end() ; i!=iEnd ; ++i )
  {
    if ( i->GetExtension() == UT_String( "bin" ) )
    {
      UT_String spriteSheetName = i->GetName( false /* no extension */ );

      size_t idx = spriteSheetName.find ( "-" );
      if ( idx != STD_String::npos )
      {
        StringPair_t sheetName;

        sheetName.first = spriteSheetName.substr( 0, idx ).utf8();
        sheetName.second = spriteSheetName.substr( idx+1 ).utf8();

        sheetNames.push_back( sheetName );
      }
    }
  }
}
コード例 #4
0
ファイル: OBJ_usdcamera.cpp プロジェクト: lvxejay/USD
OP_TemplatePair*
GusdOBJ_usdcamera::GetTemplates()
{
    /* Our common camera params come from the same initialization script
       as the standard camera.*/

    static PRM_Default primPathDef(0, "/World/main_cam");
    static PRM_Name frameName("frame", "Frame");
    static PRM_Default frameDef(0, "$FF");
    
    static PRM_Name xformName("xformmode", "Transform Mode");
    static PRM_Name xformNames[] = {
        PRM_Name("postmultctm", "Object to World"),
        PRM_Name("ctm", "Parent to World"),
        PRM_Name("obj", "Object"),
        PRM_Name("none", "None"),
        PRM_Name()
    };
    static PRM_ChoiceList xformMenu(PRM_CHOICELIST_SINGLE, xformNames);

    GusdPRM_Shared prmShared;

    static PRM_Template camTemplates[] = {
        PRM_Template(PRM_FILE, 1, &prmShared->filePathName, 0,
                     /*choicelist*/ 0, /*range*/ 0,
                     /*callback*/ 0, &prmShared->usdFileROData),
        PRM_Template(PRM_STRING, 1, &prmShared->primPathName,
                     &primPathDef),
        PRM_Template(PRM_FLT, 1, &frameName, &frameDef),
        PRM_Template(PRM_ORD, 1, &xformName, 
                     /* default*/ 0, 
                     /* choice list */ &xformMenu,
                     /* range */0,
                     /* callback */0,
                     /* spare */0,
                     /* group */0,
                     "If this node is included in a OBJ hierarchy this "
                     "should be set to 'Object'. If not, it should "
                     "be set to 'Object to World'"),
        PRM_Template()
    };
    unsigned numCamTemplates = PRM_Template::countTemplates(camTemplates);

    // for backwards compatibility with old stereo attributes {
    static PRM_Name isStereoName("isstereo", "Is Stereo");
    static PRM_Name rightEyeName( "isrighteye", "Is Right Eye" );
    static PRM_Name convergenceDistanceName("convergencedistance",
                                            "Convergence Distance");
    static PRM_Name interocularDistanceName("interoculardistance",
                                            "Interocular Distance");
    static PRM_Name leftEyeBiasName("lefteyebias", "Left Eye Bias");

    static PRM_Template stereoAttrsTemplates[] = {
        PRM_Template(PRM_TOGGLE | PRM_TYPE_INVISIBLE, 1, &isStereoName,
                     /* defaults */ 0,
                     /* choice list */ 0,
                     /* range ptr */0,
                     /* callback */0,
                     /* spare */ 0,
                     /* parmgroup*/ 1,
                     "Show mono view if off. Right or left eye view if on."),
        PRM_Template(PRM_TOGGLE | PRM_TYPE_INVISIBLE, 1, &rightEyeName,
                     /* defaults */ 0,
                     /* choice list */ 0,
                     /* range ptr */0,
                     /* callback */0,
                     /* spare */ 0,
                     /* parmgroup*/ 1,
                     "If checked, show right eye view. "
                     "Otherwise show left eye view."),
        PRM_Template(PRM_FLT | PRM_TYPE_INVISIBLE, 1, &convergenceDistanceName, 0),
        PRM_Template(PRM_FLT | PRM_TYPE_INVISIBLE, 1, &interocularDistanceName, 0),
        PRM_Template(PRM_FLT | PRM_TYPE_INVISIBLE, 1, &leftEyeBiasName,
                     /* defaults */ 0,
                     /* choice list */ 0,
                     /* range ptr */0,
                     /* callback */0,
                     /* spare */ 0,
                     /* parmgroup*/ 1,
                     "If 0, left eye view matches mono view. "
                     "If 1, right eye view matches mono view." ),
        PRM_Template()
    };
    
    unsigned numStereoAttrsTemplates = 
        PRM_Template::countTemplates(stereoAttrsTemplates);
    // }

    static PRM_Name displayFrustumName( "displayFrustum", "Display Frustum");
    static PRM_Template displayFrustum(PRM_TOGGLE, 1, &displayFrustumName, 0);

    const PRM_Template* const objTemplates = getTemplateList(OBJ_PARMS_PLAIN);
    unsigned numObjTemplates = PRM_Template::countTemplates(objTemplates);

    /* First template in common obj parms is a switcher.
       We need to modify the switcher to include our own tab.*/
    
    UT_IntArray numSwitchersOnPages, numNonSwitchersOnPages;
    PRM_Template::getSwitcherStats(objTemplates,
                                   numSwitchersOnPages,
                                   numNonSwitchersOnPages);
    unsigned oldSwitcherSize = numNonSwitchersOnPages.entries();
    
    static std::vector<PRM_Default> tabs(oldSwitcherSize+1);
    
    static PRM_Default renderPaneDefault;
    
    for(int i = 0; i < oldSwitcherSize; ++i)
    {
        tabs[i] = objTemplates->getFactoryDefaults()[i];
        
        // We want to add an item to the Render pane, displayFrustum.
        // We need to increase the item count in the switcher default.
        if(UT_String(tabs[i].getString()) == "Render")
        {
            renderPaneDefault.setString(tabs[i].getString());
            renderPaneDefault.setFloat(tabs[i].getFloat() + 1);
            tabs[i] = renderPaneDefault;
        }
    }
    tabs[oldSwitcherSize] = 
        PRM_Default(numCamTemplates + numStereoAttrsTemplates, "USD");

    static PRM_Name switcherName = *objTemplates->getNamePtr();

    static std::vector<PRM_Template> templates;
    templates.push_back(
        PRM_Template(PRM_SWITCHER, tabs.size(), &switcherName, &tabs[0]));
    
    for(std::size_t i = 1; i < numObjTemplates; ++i) 
    {
        templates.push_back( objTemplates[i] );
        if(UT_String(objTemplates[i].getNamePtr()->getToken()) == "display")
            templates.push_back(displayFrustum);
    }
    templates.insert(templates.end(), camTemplates,
                     camTemplates + numCamTemplates);
    templates.insert(templates.end(), stereoAttrsTemplates,
                     stereoAttrsTemplates + numStereoAttrsTemplates);
    templates.push_back(PRM_Template());

    static OP_TemplatePair templatePair(&templates[0], NULL);
    return &templatePair;
}
コード例 #5
0
void FabricDFGView::saveJsonData()
{
    m_op->setString(UT_String(getJSON().c_str()), CH_STRING_LITERAL, "jsonData", 0, 0);
}
コード例 #6
0
#include "tf_test.h"
#include "ut_string_class.h"

#define TFSUITE "core.af.util.stringclass"

TFTEST_MAIN("UT_String")
{
	UT_String s("foobar");

	TFPASS(s.size() == 6);
	TFPASS(s.length() == 6);

	TFFAIL(s.empty());

	TFPASS(s == "foobar");
	TFPASS(s == UT_String("foobar"));

	s += "baz";
	TFPASS(s.size() == 9);
	TFPASS(s == "foobarbaz");

	s += UT_String("42");
	TFPASS(s.size() == 11);
	TFPASS(s == "foobarbaz42");

	s += '!';
	TFPASS(s.size() == 12);
	TFPASS(s == "foobarbaz42!");

	TFPASS(s[3] == 'b');
	s[3] = 'c';
コード例 #7
0
ファイル: ap_Win32App.cpp プロジェクト: lokeshguddu/AbiWord
/*!
 * A callback for AP_Args's doWindowlessArgs call which handles
 * platform-specific windowless args.
 * return false if we should exit normally but Window should not be displayed
 */
bool AP_Win32App::doWindowlessArgs(const AP_Args *Args, bool & bSuccess)
{
	bSuccess = true;

	AP_Win32App * pMyWin32App = static_cast<AP_Win32App*>(Args->getApp());

	if (Args->m_sGeometry)
	{
		// [--geometry <X geometry string>]
		#if 0
		gint x = 0;
		gint y = 0;
		guint width = 0;
		guint height = 0;
		
		XParseGeometry(Args->m_sGeometry, &x, &y, &width, &height);

		// set the xap-level geometry for future frame use
		Args->getApp()->setGeometry(x, y, width, height, f);
		#endif

		parseAndSetGeometry(Args->m_sGeometry);
	}
	else
	if (Args->m_sPrintTo) 
	{
		if (Args->m_sFiles[0])
		{
			UT_DEBUGMSG(("DOM: Printing file %s\n", Args->m_sFiles[0]));
			AP_Convert conv ;

			if (Args->m_sMerge)
				conv.setMergeSource (Args->m_sMerge);

			if (Args->m_impProps)
				conv.setImpProps (Args->m_impProps);
			if (Args->m_expProps)
				conv.setExpProps (Args->m_expProps);
			
			UT_String s = "AbiWord: ";
			s+= Args->m_sFiles[0];
			
            UT_Win32LocaleString prn, doc;
			prn.fromASCII (Args->m_sPrintTo);
			doc.fromASCII (s.c_str());
			GR_Graphics * pG = GR_Win32Graphics::getPrinterGraphics(prn.c_str(), doc.c_str());			
            if(!pG)
			{
				// do not assert here, if the graphics creation failed, the static
				// constructor has asserted already somewhere more relevant
				return false;
			}
			
			conv.setVerbose(Args->m_iVerbose);
			conv.print (Args->m_sFiles[0], pG, Args->m_sFileExtension);
	      
			delete pG;
		}
		else
		{
			// couldn't load document
			UT_DEBUGMSG(("Error: no file to print!\n"));
			bSuccess = false;
		}

		return false;
	}

	if(Args->m_sPluginArgs)
	{
	//
	// Start a plugin rather than the main abiword application.
	//
	    const char * szName = NULL;
		XAP_Module * pModule = NULL;
		bool bFound = false;	
		if(Args->m_sPluginArgs[0])
		{
			const char * szRequest = Args->m_sPluginArgs[0];
			const UT_GenericVector<XAP_Module*> * pVec = XAP_ModuleManager::instance().enumModules ();
			UT_DEBUGMSG((" %d plugins loaded \n",pVec->getItemCount()));
			for (UT_sint32 i = 0; (i < pVec->size()) && !bFound; i++)
			{
				pModule = pVec->getNthItem (i);
				szName = pModule->getModuleInfo()->name;
				UT_DEBUGMSG(("%s\n", szName));
				if(strcmp(szName,szRequest) == 0)
				{
					bFound = true;
				}
			}
		}
		if(!bFound)
		{
			UT_DEBUGMSG(("Plugin %s not found or loaded \n",Args->m_sPluginArgs[0]));
			bSuccess = false;
			return false;
		}

//
// You must put the name of the ev_EditMethod in the usage field
// of the plugin registered information.
//
		const char * evExecute = pModule->getModuleInfo()->usage;
		EV_EditMethodContainer* pEMC = pMyWin32App->getEditMethodContainer();
		const EV_EditMethod * pInvoke = pEMC->findEditMethodByName(evExecute);
		if(!pInvoke)
		{
			UT_DEBUGMSG(("Plugin %s invoke method %s not found \n",
				   Args->m_sPluginArgs[0],evExecute));
			bSuccess = false;
			return false;
		}
		//
		// Execute the plugin, then quit
		//
		ev_EditMethod_invoke(pInvoke, UT_String("Called From App"));
		return false;
	}

	return true;
}
コード例 #8
0
/** 
 * Called when parsing the content between the start and end element tags.
 */
void ODi_MetaStream_ListenerState::charData (const gchar* pBuffer, int length)
{
    if (pBuffer && length) {
        m_charData += UT_String (pBuffer, length).c_str();
    }
}
コード例 #9
0
ファイル: ev_EditMethod.cpp プロジェクト: hfiguiere/abiword
bool ev_EditMethod_invoke (const char * methodName, const char * data)
{
  UT_return_val_if_fail(data, false);
  return ev_EditMethod_invoke ( methodName, UT_String(data) ) ;
}